Jump to content

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

?>

 

 

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.