Jump to content

While Loop Error


sws

Recommended Posts

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

This is backwards
mysql_fetch_array($standings_query) = $table_rows

it 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 such

also the word points need to be in quotes
same for name too

i.e.
$table_row['points']
Link to comment
https://forums.phpfreaks.com/topic/26577-while-loop-error/#findComment-121568
Share on other sites

[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 on

the only real difference is that you can do echo statements on the fly with short tags

for 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

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 a
comparison operator such as ==. Thus, if I'm not mistaking, (i'm new to PHP), this will
always 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.