Enjoy an ad free experience by logging in. Not a member yet?
Register .
05-06-2009, 08:54 PM
PM User |
#1
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
php code throwing up whitespace error?
Hi All
i have this piece of code which is throwing up a warning
PHP Code:
$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
Code:
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
PHP Code:
< div class= 'itemTitle' > $row [ 'title' ]</ div >
but i cant see anything wrong,
can anyone see the problem?
thanks
Luke
05-06-2009, 08:59 PM
PM User |
#2
Gütkodierer
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
Code:
<div class='itemTitle'>{ $row['title']} </div>
Users who have thanked venegal for this post:
05-06-2009, 09:13 PM
PM User |
#3
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
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 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 & Price Comparision - For the smarter shopper" alt="Kernow Connect - Online Shopping & 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
05-06-2009, 09:17 PM
PM User |
#4
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
ok mate ive solved it was printing out the "}" which the php didnt like
cheers
05-06-2009, 09:19 PM
PM User |
#5
Gütkodierer
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
There are some strange things going on with your string.
PHP Code:
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 ++;
05-06-2009, 09:32 PM
PM User |
#6
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
i think my entire code is strange lol
is there anything wrong with this
PHP Code:
$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
05-06-2009, 09:39 PM
PM User |
#7
Gütkodierer
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
Try
PHP Code:
$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.
Last edited by venegal; 05-06-2009 at 09:52 PM ..
05-06-2009, 09:48 PM
PM User |
#8
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
its still displaying no data to display
05-06-2009, 09:56 PM
PM User |
#9
Gütkodierer
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
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
05-06-2009, 10:11 PM
PM User |
#10
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
ok i have printed out $itemdata and here is an example of the result
Code:
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
05-06-2009, 10:25 PM
PM User |
#11
Gütkodierer
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
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.
05-06-2009, 10:40 PM
PM User |
#12
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
hi mate,
ok code is sorted
and i have changed my query to
PHP Code:
$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
05-06-2009, 10:46 PM
PM User |
#13
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
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
PHP Code:
while ( $row = mysql_fetch_array ( $query )){
instead of
PHP Code:
while ( $row = mysql_fetch_array ( $item_query )){
typical a type
but its working now
thank you very much for your help
really appreciate it
Luke
05-06-2009, 10:48 PM
PM User |
#14
Gütkodierer
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
Alright, that error makes it much easier.
Your resultset is named $item_query, yet you try to fetch it with
PHP Code:
$row = mysql_fetch_array ( $query )
Change that to
PHP Code:
$row = mysql_fetch_array ( $item_query )
Edit: Oh, too late.
05-06-2009, 10:54 PM
PM User |
#15
Senior Coder
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
lol stupid error, so fustrating!!!!
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 11:03 PM .
Advertisement
Log in to turn off these ads.