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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.