leeh14 Posted May 13, 2010 Share Posted May 13, 2010 Hi, Right I have a 'while loop' getting data from the mysql database, but what I want to do is once the loop has retrieved 4 data sets function stops running. How is this done? Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/ Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 Please post your current code. Ken Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057761 Share on other sites More sharing options...
leeh14 Posted May 13, 2010 Author Share Posted May 13, 2010 So yeah i want the while to run 4 times then stop? $query = "select * from videos"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $tit_1 = $row["title"]; $des_1 = $row["des"]; $len_1 = $row["length"]; $url_1 = $row["URL"]; $img_1 = $row["image"]; $sli_1 = $row["slider"]; $del = $row["ID"]; echo "<li><a href='$page?\"?goto=true&id=".$del."'><img src='Tutorials/slider_thumbnails/$sli_1' width = '960px' height='400px' alt='CssTemplate Preview' /></a></li>"; } ?> Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057765 Share on other sites More sharing options...
leeh14 Posted May 13, 2010 Author Share Posted May 13, 2010 Is there an answer out there?? Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057799 Share on other sites More sharing options...
Joshua4550 Posted May 13, 2010 Share Posted May 13, 2010 Like so? $query = "select * from videos LIMIT 4"; Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057802 Share on other sites More sharing options...
leeh14 Posted May 13, 2010 Author Share Posted May 13, 2010 Thank you kindly! Works a charm! Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057811 Share on other sites More sharing options...
Joshua4550 Posted May 13, 2010 Share Posted May 13, 2010 No problemo. Please mark the topic as solved. Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057820 Share on other sites More sharing options...
leeh14 Posted May 13, 2010 Author Share Posted May 13, 2010 One more thing however, if i wanted to get the last 4 data sets from the data (e.g the ones with the highest ID number) how would i do that? Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057835 Share on other sites More sharing options...
Psycho Posted May 13, 2010 Share Posted May 13, 2010 A field for date added would be better than using the ID, but with what you have: //First four $query = "SELECT * FROM videos ORDER BY ID ASC LIMIT 4"; //Last four $query = "SELECT * FROM videos ORDER BY ID DESC LIMIT 4"; Of course the last four will be in reverse order. If you need them in ascending order I think this will do it //Last four in ascending order $query = "SELECT * FROM (SELECT * FROM videos ORDER BY ID DESC LIMIT 4) ORDER BY ID ASC"; Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057839 Share on other sites More sharing options...
Joshua4550 Posted May 13, 2010 Share Posted May 13, 2010 What he said. But also like he said, you may want to make it a date - best in milliseconds, so when you insert into mySQL: microtime() Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057862 Share on other sites More sharing options...
leeh14 Posted May 13, 2010 Author Share Posted May 13, 2010 Another one solved this forum is amazing !! Link to comment https://forums.phpfreaks.com/topic/201638-set-amount/#findComment-1057882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.