...

View Full Version : php code throwing up whitespace error?



LJackson
05-06-2009, 09:54 PM
Hi All

i have this piece of code which is throwing up a warning


$itemdata = "SELECT *
FROM category_data
WHERE page_category = 'Entertainment' AND subcat_id = '$subcategory_list[$sub_count]'";

$item_query=mysql_query($itemdata);
$num_rows = mysql_num_rows($item_query);

if ($num_rows == 0){
echo "No Results Please Go Back And Try Again";
}
else {
while ($row = mysql_fetch_array($query)){

print "<div class='item'>
<div class='itemIMG'></div>
<div class='itemTitle'>$row['title']</div>
<div class='itemInfo'></div>
<div class='itemButton'><div>
</div>

}
}

warning

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /customers/kernow-connect.com/kernow-connect.com/httpd.www/entertainmentPCtest.php on line 316

and line 316 is

<div class='itemTitle'>$row['title']</div>

but i cant see anything wrong,

can anyone see the problem?

thanks
Luke

venegal
05-06-2009, 09:59 PM
<div class='itemTitle'>{$row['title']}</div>

LJackson
05-06-2009, 10:13 PM
thanks mate that solved that problem
but its now saying un expected end which is usually a missing "}" but i cant see it :(

here is my code

<?php
$user_name = "";
$password = "";
$database = "";
$server = "";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
?>

<div id='header'>
<div id='logo'>
<h1>
<a href="index.php" target="_self">
<img src='images/logo/thelogo2.png'
title="Kernow Connect -
Online Shopping &amp; Price Comparision - For the smarter shopper"
alt="Kernow Connect -
Online Shopping &amp; Price Comparision - For the smarter shopper"
border='0' /></a></h1>
</div>

<div class="slogantext">
<h1>Online Shopping And Price Comparison</h1>
</div>

</div>

<div id="wrapper">

<div id="navlink">

<div class='link'>
<img src="images/links/entertainmentlink.png" />
</div>
<div class='link'>
<img src="images/links/computinglink.png" />
</div>
<div class='link'>
<img src="images/links/electronicstlink.png" />
</div>
<div class='link'>
<img src="images/links/clothinglink.png" />
</div>
<div class='link'>
<img src="images/links/misclink.png" />
</div>

</div>

<?php

$category_list = array("DVD", "CD", "Video Games", "Blu-Ray", "Books");
$subcategory_list = array("Bestsellers","New Releases","Most Gifted");
$cat_count = 0;
foreach ($category_list as $category){
print "<div class='catsections'>
<div class='catheader'>
<div class='category_name'><h1>$category_list[$cat_count]</h1></div>
</div>

<div class='cattop'>
<div class='cattop_header'>Kernow Connect Pick Of The Week</div>
<div class='cattop_item'></div>
<div class='cattop_desc'></div>
</div>";

$sub_count = 0;

foreach($subcategory_list as $subcategory){
print "<div class='top3'>
<div class='subcat_header'>$subcategory_list[$sub_count]</div>";

$itemdata = "SELECT *
FROM category_data
WHERE page_category = 'Entertainment' AND subcat_id = '$subcategory_list[$sub_count]'";

$item_query=mysql_query($itemdata);
$num_rows = mysql_num_rows($item_query);

if ($num_rows == 0){
echo "No Results Please Go Back And Try Again";
}
else {
while ($row = mysql_fetch_array($query)){

print "<div class='item'>
<div class='itemIMG'></div>
<div class='itemTitle'>{$row['title']}</div>
<div class='itemInfo'></div>
<div class='itemButton'><div>
</div>

}
}
}
</div>";
$sub_count ++;

}

$cat_count ++;
}

?>

</div>
</body>
</html>

cheers mate
Luke

LJackson
05-06-2009, 10:17 PM
ok mate ive solved it was printing out the "}" which the php didnt like :)

cheers

venegal
05-06-2009, 10:19 PM
There are some strange things going on with your string.



if ($num_rows == 0){
echo "No Results Please Go Back And Try Again";
} else {
while ($row = mysql_fetch_array($query)){
print "<div class='item'>
<div class='itemIMG'></div>
<div class='itemTitle'>{$row['title']}</div>
<div class='itemInfo'></div>
<div class='itemButton'><div>
</div>";
}
}
$sub_count ++;

LJackson
05-06-2009, 10:32 PM
i think my entire code is strange lol

is there anything wrong with this

$itemdata = "SELECT *
FROM category_data
WHERE page_category = 'Entertainment' AND subcat_id = '$subcategory_list[$sub_count]'";

$sub_count is a number which increases by one each time
and $subcategory_list is an array

but its not returning any records?

any ideas
Cheers
Luke

venegal
05-06-2009, 10:39 PM
Try



$itemdata = "SELECT *
FROM category_data
WHERE page_category = 'Entertainment' AND subcat_id = '{$subcategory_list[$sub_count]}'";

Dumping complex code (at least more complex than a simple variable) straight into a double quoted string is usually asking for trouble.

LJackson
05-06-2009, 10:48 PM
its still displaying no data to display :(

venegal
05-06-2009, 10:56 PM
Well I can't really debug that without your database.
Something you could do:
1.) echo $itemdata and see if the query looks ok
2.) check that query against your database and make sure that there actually are entries that fit

LJackson
05-06-2009, 11:11 PM
ok i have printed out $itemdata and here is an example of the result

SELECT * FROM category_data WHERE page_category = 'Entertainment' AND subcat_id = 'New Releases'

which looks right?

im gonna tidy up my code because its messy and missing a div somewhere which i want to fix which will hopefully make the job easier for you :)

if you can think of any other ideas which could help i'd really like to hear them
:)

i'll be back once my code is tidy lol
cheers

venegal
05-06-2009, 11:25 PM
Well that missing div won't do anything; what it's boiling down to right now, is that the query, which looks about right, doesn't yield any results.

So, the question is, are you sure that in the table "category_data" you have a row with a page_category of "Entertainment" and a subcat_id of "New Releases"?

For example, "_id" suggests that it's a numerical value, but I don't know how you set up your database.

LJackson
05-06-2009, 11:40 PM
hi mate,

ok code is sorted

and i have changed my query to

$itemdata = "SELECT *
FROM category_data
WHERE page_category = 'Entertainment'
AND cat_id = '$category_list[$cat_count]' AND subcat_id = '$subcategory_list[$sub_count]'";


which when printed out displays
SELECT * FROM category_data WHERE page_category = 'Entertainment' AND cat_id = 'DVD' AND subcat_id = 'Bestsellers'

which is correct :)

when i type this into my database sql query it displays the correct 3 records :)

i am getting the following error on my php page
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /customers/kernow-connect.com/kernow-connect.com/httpd.www/entertainmentPCtest.php on line 329

i will double check my fields and data in my database to to make sure its correct :)

LJackson
05-06-2009, 11:46 PM
grrrrrrrr bloody hell (excuse my french) lol

found my problem
it was not that query that was the problem but the bit underneath :(

i had

while ($row = mysql_fetch_array($query)){

instead of

while ($row = mysql_fetch_array($item_query)){

typical a type

but its working now :D

thank you very much for your help
really appreciate it

Luke

venegal
05-06-2009, 11:48 PM
Alright, that error makes it much easier.
Your resultset is named $item_query, yet you try to fetch it with

$row = mysql_fetch_array($query)
Change that to

$row = mysql_fetch_array($item_query)

Edit: Oh, too late.

LJackson
05-06-2009, 11:54 PM
lol stupid error, so fustrating!!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum