jakebur01 Posted October 24, 2007 Share Posted October 24, 2007 I have this script that displays verses out of the bible. The problem is that it is only displaying one verse. I would like for it to display about 10 verses in a row. Random selections though. $result = mysql_query("SELECT * FROM bible ORDER BY RAND() LIMIT 1 "); // WHERE catid <> 'TBP' while($myrow = mysql_fetch_array($result)) { $title = $myrow['book'].' '.$myrow['chapter'].' : '.$myrow['verse'].'<br /> '.$myrow['text']; echo $title; echo "<br />"; echo "<br />"; } Link to comment https://forums.phpfreaks.com/topic/74537-solved-selecting-10-rows-together/ Share on other sites More sharing options...
pocobueno1388 Posted October 24, 2007 Share Posted October 24, 2007 You have "LIMIT 1" in your query, that means it's only going to display one row. Change that to "LIMIT 10". Link to comment https://forums.phpfreaks.com/topic/74537-solved-selecting-10-rows-together/#findComment-376754 Share on other sites More sharing options...
jakebur01 Posted October 24, 2007 Author Share Posted October 24, 2007 I tried that but it is selecting and displaying 10 different random rows. I am wanting a randow selection ,but 10 rows together. EX. 40 7 : 15 40 7 : 16 40 7 : 17 40 7 : 18 40 7 : 19 40 7 : 20 40 7 : 21 40 7 : 22 40 7 : 23 40 7 : 24 Link to comment https://forums.phpfreaks.com/topic/74537-solved-selecting-10-rows-together/#findComment-376755 Share on other sites More sharing options...
pocobueno1388 Posted October 24, 2007 Share Posted October 24, 2007 Okay, I see. <?php $getNums = mysql_query("SELECT MAX(id) as max, MIN(id) as min FROM bible"); $row = mysql_fetch_assoc($getNums); $max = $row['max'] - 10; $min = $row['min']; $rand = rand($min, $max); $stop = $rand + 10; $result = mysql_query("SELECT * FROM bible LIMIT $rand, $stop"); // WHERE catid <> 'TBP' while($myrow = mysql_fetch_array($result)){ $title = $myrow['book'].' '.$myrow['chapter'].' : '.$myrow['verse'].'<br /> '.$myrow['text']; echo $title; echo "<br />"; echo "<br />"; } ?> Give that a try... Link to comment https://forums.phpfreaks.com/topic/74537-solved-selecting-10-rows-together/#findComment-376760 Share on other sites More sharing options...
jakebur01 Posted October 24, 2007 Author Share Posted October 24, 2007 it's doing it ,but it's looping through the whole database and selecting & displaying sets of 10 over and over Link to comment https://forums.phpfreaks.com/topic/74537-solved-selecting-10-rows-together/#findComment-376769 Share on other sites More sharing options...
rajivgonsalves Posted October 24, 2007 Share Posted October 24, 2007 You could try SELECT * FROM bible ORDER BY (RAND()*1000) LIMIT 10 Link to comment https://forums.phpfreaks.com/topic/74537-solved-selecting-10-rows-together/#findComment-376872 Share on other sites More sharing options...
pocobueno1388 Posted October 24, 2007 Share Posted October 24, 2007 Try <?php $getNums = mysql_query("SELECT MAX(id) as max, MIN(id) as min FROM bible"); $row = mysql_fetch_assoc($getNums); $max = $row['max'] - 10; $min = $row['min']; $rand = rand($min, $max); $stop = $rand + 10; $result = mysql_query("SELECT * FROM bible LIMIT $rand, $stop"); // WHERE catid <> 'TBP' $i = 0; while($myrow = mysql_fetch_array($result)){ $title = $myrow['book'].' '.$myrow['chapter'].' : '.$myrow['verse'].'<br /> '.$myrow['text']; echo $title; if ($i == 9) break; echo "<br />"; echo "<br />"; $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/74537-solved-selecting-10-rows-together/#findComment-377002 Share on other sites More sharing options...
jakebur01 Posted October 24, 2007 Author Share Posted October 24, 2007 Yes, that worked great! Thank you pocobueno. Link to comment https://forums.phpfreaks.com/topic/74537-solved-selecting-10-rows-together/#findComment-377004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.