ecabrera Posted April 13, 2012 Share Posted April 13, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/260846-do-while/ Share on other sites More sharing options...
xyph Posted April 13, 2012 Share Posted April 13, 2012 You have to define your variables within the do..while() loop. Quote Link to comment https://forums.phpfreaks.com/topic/260846-do-while/#findComment-1336921 Share on other sites More sharing options...
ecabrera Posted April 13, 2012 Author Share Posted April 13, 2012 thanks fixed it ok so i want to show the last three results can i do this while($rows = mysql_fetch_assoc($query) && $rows <= 3) Quote Link to comment https://forums.phpfreaks.com/topic/260846-do-while/#findComment-1336922 Share on other sites More sharing options...
ecabrera Posted April 13, 2012 Author Share Posted April 13, 2012 ok so i try this and it gives me back 1 image i dont why Quote Link to comment https://forums.phpfreaks.com/topic/260846-do-while/#findComment-1336925 Share on other sites More sharing options...
xyph Posted April 13, 2012 Share Posted April 13, 2012 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 } Quote Link to comment https://forums.phpfreaks.com/topic/260846-do-while/#findComment-1336927 Share on other sites More sharing options...
ecabrera Posted April 13, 2012 Author Share Posted April 13, 2012 ok thanks Quote Link to comment https://forums.phpfreaks.com/topic/260846-do-while/#findComment-1336928 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.