Jump to content

while


ecabrera

Recommended Posts

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>
&#8226; <a href="viewp?view=<?php echo $id; ?>"><?php echo $title; ?></a><br>
&#8226; <a href="viewp?view=<?php echo $id; ?>"><?php echo $title; ?></a><br>
</td>
</tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/254313-while/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/254313-while/#findComment-1303977
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/254313-while/#findComment-1303986
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.