Jump to content

[SOLVED] selecting 10 rows together


jakebur01

Recommended Posts

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

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

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

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++;
}

?>

 

 

Archived

This topic is now archived and is closed to further replies.

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