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
Share on other sites

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
Share on other sites

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
Share on other sites

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.