Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql_fetch_object in a while loop and row->[attribute name]
    text
    copied!<p>I'm very new to web programming, and I'm working through a Vikram Vaswani's How to Do Everything With PHP and MySQL. Near the end, he shows how to do a web program which shows news items and allows the user to edit and add different news items. The code doesn't seem to work and I've tweaked it to get it to work, but I'm still confused. In particular, I have the following code (this website isn't handling the breaks very well)</p> <pre><code>// if records present if (mysql_num_rows($result) &gt; 0) { // iterate through resultset // print article titles while($row == mysql_fetch_object($result)); { ?&gt; &lt;li&gt;&lt;a href="story.php?Ticker=&lt;?php echo $row-&gt;Ticker;?&gt;"&gt;&lt;?php echo $row-&gt;StockName;?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php $row = mysql_fetch_object($result); echo $row-&gt;Ticker; echo $row-&gt;StockName; &lt;br&gt; </code></pre> <p>Now, the book had <code>while ($row = mysql_fetch_object($result));</code> - but that didn't do anything. So I changed it to an equal comparison operator. I'm thinking that with the <code>$row = mysql_fetch_object($result)</code> at the bottom in the loop, it should move onto the next row of the table since this is the normal behavior per <a href="http://us2.php.net/manual/en/function.mysql-fetch-object.php" rel="nofollow">http://us2.php.net/manual/en/function.mysql-fetch-object.php</a> and per my own testing. I can do this differently with a for loop or something but I would like to figure out why it isn't working how I expect here.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload