Gossamer Forum
Home : General : Internet Technologies :

Separating MySQL results

Quote Reply
Separating MySQL results
It's been ages since I played with PHP but I'm back at it and I've got a problem. Of course when I have a problem, I come here...

I want to separate 3 results that are taken from 1 mysql query. This is as far as I've gotten:

Code:

$prev_verse = $_GET['verse'] - 1;
$next_verse = $_GET['verse'] + 1;

$sql = @mysql_query("SELECT text FROM bible_ot WHERE book = '$_GET[book]' AND
chapter = '$_GET[chapter]' AND verse = '$prev_verse' OR book = '$_GET[book]' AND
chapter = '$_GET[chapter]' AND verse = '$_GET[verse]' OR book = '$_GET[book]' AND
chapter = '$_GET[chapter]' AND verse = '$next_verse'");


I know there's a big while statement or something that I need but I'm lost now... I just can't figure out how to manipulate arrays the way I want. Eg: Put it all into an array "mysql_fetch_array" then separate them into their own variables or callable id's ($var[first statement], $var[second statement], etc.) Main thing is, I want to break that array up into 3 variables so I can use each one individually rather than limit them all to that one while statement.
Quote Reply
Re: [JoFrRi] Separating MySQL results In reply to
I would just use something like;

$sql = @mysql_query("SELECT text FROM bible_ot WHERE (book = '$_GET[book]' AND chapter = '$_GET[chapter]' AND verse = '$prev_verse') OR (book = '$_GET[book]' AND chapter = '$_GET[chapter]' AND verse = '$_GET[verse]') OR (book = '$_GET[book]' AND chapter = '$_GET[chapter]' AND verse = '$next_verse')");

Actually, wouldn't this do what you want?

SELECT text FROM bible_ot WHERE book = '$_GET[book]' AND chapter = '$_GET[chapter]' AND (verse = '$prev_verse' OR verse = '$_GET[verse]' OR verse = '$next_verse')

?

Regarding the "while" did you try somethingl like this? (no guarantees =));

Code:
// Connecting, selecting database
$link = mysql_connect("$db_host", "$db_user", "$db_password")
or die("Could not connect");

//select the database
mysql_select_db("$db")
or die("Could not select database");

// the query
$query = "SELECT text FROM bible_ot WHERE (book = '$_GET[book]' AND chapter = '$_GET[chapter]' AND verse = '$prev_verse') OR (book = '$_GET[book]' AND chapter = '$_GET[chapter]' AND verse = '$_GET[verse]') OR (book = '$_GET[book]' AND chapter = '$_GET[chapter]' AND verse = '$next_verse')";
$result=mysql_query($query)
or die ('<H1 align=center><font color=red>Bad Database Request</font></H2> in :<BR>'
.__FILE__ .' line '.__LINE__
.'<BR><br /><b>The query used was:</b><BR><BR> '.$query
.'<BR><br /><b>MySQL says</b><BR><BR> '.mysql_error();

while ($row = mysql_fetch_array($result)) {

echo "Entry: " . $row['text'] . "\n";

 }

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates