Hey everyone. I've used this method to loop through data from a database for at least two years. Today I wrote a function to retrieve rants from my database, sorted by ID, and then create and return the code for them. When I use it, however, it only loops once (which is why I have the $a++; and echo "<br>".$a."<br>"; in there. It displays "1"). It displays the latest result perfectly fine but won't loop more than once.
function list_new_rants()
{
$sql = "SELECT * FROM rants ORDER BY id DESC";
$query = mysql_query($sql) or die(mysql_error());
while($assoc = mysql_fetch_assoc($query)){
$a++;
$sql = "SELECT * FROM users WHERE id=".$assoc['author_id']."";
$query = mysql_query($sql) or die(mysql_error());
$ruser_info = mysql_fetch_assoc($query);
$words = explode(" ",$assoc['content']);
$code .= "<table width=\"100%\" border=\"1\">\n";
$code .= "<tr><td><h3><a
href=\"?p=rant.php&a=3&id=".$assoc['id']."\"><i>".$assoc['subject']."</i></a> by
".$ruser_info['username']."</h3></td></tr>\n";
$code .= "<tr><td><i>";
if(count($words) < 30){
for($i = 0; $i < count($words); $i++){
$code .= "".$words[$i]." ";
}
} else {
for($i = 0; $i < 30; $i++){
$code .= "".$words[$i]." ";
}
$code .= "...";
}
$code .= "</i></td></tr>\n";
$code .= "</table><br>\n\n";
}
echo "<br>".$a."<br>";
return $code;
}