ecabrera Posted January 4, 2012 Share Posted January 4, 2012 help i want my to output my stuff in the db but it show the same stuff over again here check it out <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM p WHERE section='gtkphp'"); while($rows = mysql_fetch_assoc($query)){ $id = $rows['id']; $title = $rows['title']; $body = $rows['body']; } mysql_close(); ?> <table id="barTop"> <tr id="sign"> <td id="blue"><b>Pages</b></td> </tr> <tr> <td> • <a href="viewp?view=<?php echo $id; ?>"><?php echo $title; ?></a><br> • <a href="viewp?view=<?php echo $id; ?>"><?php echo $title; ?></a><br> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254313-while/ Share on other sites More sharing options...
scootstah Posted January 4, 2012 Share Posted January 4, 2012 That's not how it works. You need to put everything in the while loop that you want repeated. I imagine you want something like: <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM p WHERE section='gtkphp'"); ?> <table id="barTop"> <tr id="sign"> <td id="blue"><b>Pages</b></td> </tr> <?php while($rows = mysql_fetch_assoc($query)): ?> $id = $rows['id']; $title = $rows['title']; $body = $rows['body']; <tr> <td> • <a href="viewp?view=<?php echo $id; ?>"><?php echo $title; ?></a><br> • <a href="viewp?view=<?php echo $id; ?>"><?php echo $title; ?></a><br> </td> </tr> <?php endwhile; mysql_close(); ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254313-while/#findComment-1303977 Share on other sites More sharing options...
ecabrera Posted January 4, 2012 Author Share Posted January 4, 2012 let me try it Quote Link to comment https://forums.phpfreaks.com/topic/254313-while/#findComment-1303982 Share on other sites More sharing options...
scootstah Posted January 4, 2012 Share Posted January 4, 2012 Whoops, made an error. Updated: <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM p WHERE section='gtkphp'"); ?> <table id="barTop"> <tr id="sign"> <td id="blue"><b>Pages</b></td> </tr> <?php while($rows = mysql_fetch_assoc($query)): $id = $rows['id']; $title = $rows['title']; $body = $rows['body']; ?> <tr> <td> • <a href="viewp?view=<?php echo $id; ?>"><?php echo $title; ?></a><br> • <a href="viewp?view=<?php echo $id; ?>"><?php echo $title; ?></a><br> </td> </tr> <?php endwhile; mysql_close(); ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/254313-while/#findComment-1303986 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.