Hi there everyone,
I'm trying to check for the number of results and if the number is greater than 0, loop a printing of the results.
The problem is, it's looping the correct number of times, but it's only printing the last result in the database table. All other results neglect to get printed.
Here's my code:
$query = "SELECT view_count, public, title FROM ".$prefix."templates WHERE owner='$id'";
$result = mysql_query($query) or die('MySQL error: ' . mysql_error() . '<hr/>' . $query);
$count=mysql_num_rows($result);
if($count==0){
echo("You currently do not have any templates stored with us. Would you like to <a href='board.php'>create one</a>?");
}else{
echo("<table width='90%' border='1' cellpadding='1' cellspacing='1'>
<tr>
<td align='center'><b>Title</b></td>
<td align='center'><b>Public</b></td>
<td align='center'><b>Views</b></td>
</tr>");
$result = mysql_query ($query);
while ($row = mysql_fetch_assoc ($result)) {
$view_count = $row['view_count'];
$public = $row['public'];
$title = $row['title'];
echo("<tr>
<td align='center'>
".$title."
</td>
<td align='center'>
");
echo $public;
if($public=='0'){
echo("No");
}else{
echo("Yes");
}
echo("
</td>
<td align='center'>
".$view_count."
</td>
</tr>");
}
echo("
</table>");
}
I imagine I've just messed something up in my query, but I can't find it. Any help would be appreciated 🙂
thanks,
json