Jump to content

Recommended Posts

why does this not show all the things

the do and while loop thorught the same picture but there are other picture but its not looping throught them

 

<?php
include "staff/scripts/connect.php";

$query = mysql_query("SELECT * FROM headlines");
$rows = mysql_fetch_assoc($query);

$author = stripslashes($rows['author']);
$date = stripslashes($rows['date']);
$picture = stripslashes($rows['picture']);
$headline = stripslashes($rows['headline']);

mysql_close();
?>
<h2 class="boxtitle">Latest Headlines</h2>
<?php do{ ?>
<img src="staff/headlineimg/<?php echo $picture; ?>" width="100px" height="90px"></img>
<?php }while($rows = mysql_fetch_assoc($query))?>
</div>
<div id="box2">
<h2 class="boxtitle">Video Picks</h2>
</div>
<div id="box3">
<h2 class="boxtitle">Latest Reviews</h2>
</div>

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

Do that in your query. Do you have some sort of unique id? If you don't, you should add one.

http://www.homeandlearn.co.uk/php/php12p3.html

 

Use a query like

SELECT * FROM headlines ORDER BY id DESC LIMIT 3

 

ORDER BY id DESC will start looking for rows from the largest id to the least.

LIMIT 3 will only grab the first 3 rows matched

No WHERE clause means any row will be matched.

 

Don't use

do {
   //code
} while( $row = .... );

 

Instead, use

while( $row = ... ) {
   $picture = $row['pic...;
   // code
}

Link to comment
https://forums.phpfreaks.com/topic/260846-do-while/#findComment-1336927
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.