I have read about the function on php.net and that has still not answered my question. I know a beginners amount of C and I've just started using php. Normally in C if you were to do a while loop there needs to be some condition to advance the loop to a point where it will no longer be valid like so:
while (x >= 10)
{
printf("...";
printf("x \n";
x++;
}
However in my php script that I'm using for a pm message system I have a while loop like this:
while($row2 = mysql_fetch_array($query))
followed by:
{
echo "<table border=1>";
echo "<tr><td>";
echo "Message #: ";
echo $row['id'];
echo "</td></tr>";
echo "<tr><td>";
echo "To: ";
echo $row['to'];
echo "</td></tr>";
echo "<tr><td>";
echo "From: ";
echo $row['from'];
echo " ";
echo "</td></tr>";
echo "<tr><td>";
echo "Message: ";
echo $row['message'];
echo "</td></tr>";
echo "</br>";
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2></td></tr>
<tr><td></td><td>
<input type="hidden" name="id" maxlength="32" value = "<?php echo $row['id']; ?>">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="delete" value="Delete PM # <?php echo $row['id']; ?>">
</td>
<td colspan="2" align="right">
<input type="submit" name="reply" value="Reply to <?php echo $row['from']; ?>">
</td></tr>
</table>
<?php } ?>
How exactly does this work, from a C background it would seem almost like this would stay in the same spot, printing out the same "array fetch" 'row' from the same "$query" every time we go through the loop....
Is there a way I can write this to give me a better logical understanding of whats going on? like saying:
$i=0;
while ($row = ($i+mysql_fetch_array($query)) {
...
...
$i++;}
I know that probably wont work but how does this function increment itself? And is there a way to write it where it would actually have some sort of incrementation visible in the code?
Thank you
mysql_*
functions. They are no longer maintained and community has begun the deprecation process. Instead you should learn about prepared statements and use either PDO or MySQLi. If you care to learn, here is a quite good PDO-related tutorial. – Second Rikudo May 8 '12 at 17:23