daveh33 Posted January 4, 2008 Share Posted January 4, 2008 while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = $row['id']; $name = $row['name']; $lup = $row['lastupdate']; $tb = $row['tablename']; $lastupdated = date("jS F Y H:i",strtotime($lup)); if ($tb) { $result = mysql_query("SELECT * from $tb"); $num = mysql_num_rows($result); } echo " </tr><tr><td><p align=\"center\">$id</td> <td><p align=\"center\">$name</td> <td><p align=\"center\"><a href=\"managenumbers.php?id=$id\">$num</a></td> <td><p align=\"center\">$lastupdated</td> <td><p align=\"center\"><a href=\"edit.php?function=list&id=$id\"><img src=\"edit.gif\" border=\"0\"></a></td> <td><p align=\"center\"><a href=\"delete.php?function=list&id=$id\"><img src=\"delete.gif\" border=\"0\"></a></td>"; } I have the above code, there is 1 row in my table and $num=4 Instead of it just showing 1 row - it shows 4... any ideas why? Guess its something to do with the numrows during the while statement? Quote Link to comment https://forums.phpfreaks.com/topic/84461-solved-while-statement-showing-duplicates/ Share on other sites More sharing options...
rajivgonsalves Posted January 4, 2008 Share Posted January 4, 2008 its because of this if ($tb) { $result = mysql_query("SELECT * from $tb"); $num = mysql_num_rows($result); } your overwriting $result Quote Link to comment https://forums.phpfreaks.com/topic/84461-solved-while-statement-showing-duplicates/#findComment-430288 Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 <?php while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $name = $row['name']; $lup = $row['lastupdate']; $tb = $row['tablename']; $lastupdated = date("jS F Y H:i",strtotime($lup)); if (isset($tb)) { $result = mysql_query("SELECT * from $tb"); $num = mysql_num_array($result); echo " </tr><tr><td><p align=\"center\">$id</td> <td><p align=\"center\">$name</td> <td><p align=\"center\"><a href=\"managenumbers.php?id=$id\">$num</a></td> <td><p align=\"center\">$lastupdated</td> <td><p align=\"center\"><a href=\"edit.php?function=list&id=$id\"><img src=\"edit.gif\" border=\"0\"></a></td> <td><p align=\"center\"><a href=\"delete.php?function=list&id=$id\"><img src=\"delete.gif\" border=\"0\"></a></td>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84461-solved-while-statement-showing-duplicates/#findComment-430298 Share on other sites More sharing options...
daveh33 Posted January 4, 2008 Author Share Posted January 4, 2008 Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/84461-solved-while-statement-showing-duplicates/#findComment-430299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.