sws Posted November 8, 2006 Share Posted November 8, 2006 Hi,I've written a query to pull all of my data and sort it by a column in descending order.I'm getting the following error: [b]parse error, unexpected '=' in hockey_contests.php on line 47[/b]Can anybody spot the error ?Thanks in advance ![code] <table> <?$standings_sql = "SELECT * FROM nhl_teams ORDERBY points DESC";$standings_query = mysql_query($standings_sql);while(mysql_fetch_array($standings_query) = $table_rows){ ?> <tr> <td colspan="2"> <h3>League Leaders</h3> </td> </tr> <tr> <td> <?=$table_row[name]?> </td> <td> <?=$table_row[points]?> </td> </tr> <?}?> </table>[/code] Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/ Share on other sites More sharing options...
Kano Posted November 8, 2006 Share Posted November 8, 2006 <?php echo "$table_row[name]" ?> Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121565 Share on other sites More sharing options...
Zane Posted November 8, 2006 Share Posted November 8, 2006 This is backwardsmysql_fetch_array($standings_query) = $table_rowsit should be$table_rows = mysql_fetch_array($standings_query)Furthermore, you need to call it $table_row instead so it will work.seeing as how you're calling $table_row[points] and suchalso the word points need to be in quotessame for name tooi.e.$table_row['points'] Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121568 Share on other sites More sharing options...
Kano Posted November 8, 2006 Share Posted November 8, 2006 does <? work the same as <?php Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121573 Share on other sites More sharing options...
Zane Posted November 8, 2006 Share Posted November 8, 2006 [quote author=Kano link=topic=114272.msg464894#msg464894 date=1163000588]does <? work the same as <?php[/quote]yes, as long as you have short_tags turned onthe only real difference is that you can do echo statements on the fly with short tagsfor instance<?="stuff" ?>is the equivalent of<?php echo 'stuff" ?> Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121575 Share on other sites More sharing options...
Kano Posted November 8, 2006 Share Posted November 8, 2006 What and how is short tags turned on ? thanks Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121577 Share on other sites More sharing options...
sws Posted November 8, 2006 Author Share Posted November 8, 2006 Excellent. Thanks for your help. Problem solved !! Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121594 Share on other sites More sharing options...
Zane Posted November 8, 2006 Share Posted November 8, 2006 in your php.ini filelook for the first occurance of short_tagsand set it to on, or true or whatever the positive value is supposed to be Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121598 Share on other sites More sharing options...
cmazur Posted November 8, 2006 Share Posted November 8, 2006 Just one more thing concerning your while loop.Although I'm not sure if it will make any difference to your problems or not.In your conditional statement, you are using an assignment operator = as opposed to acomparison operator such as ==. Thus, if I'm not mistaking, (i'm new to PHP), this willalways cause the conditional to be true. [code]while(mysql_fetch_array($standings_query) == $table_rows){ ?> <tr> <td colspan="2"> <h3>League Leaders</h3> </td> </tr> <tr> <td> <?=$table_row[name]?> </td> <td> <?=$table_row[points]?> </td> </tr> <?}[/code] Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121600 Share on other sites More sharing options...
Zane Posted November 8, 2006 Share Posted November 8, 2006 that mostly concerns IF statementsit won't always return true because by the time it gets to the last recordof your querymysql_fetch_array will return FALSE.stopping the loop Link to comment https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.