Jump to content

query fetch row


thefollower

Recommended Posts

I have a code which checks if the row is not found but then i have another line to get the row that is found straight after... but for some odd reason say i have 2 rows in the database itll only show the second row... i was wondering if its because i have a fetch row twice as i will show below:

 

$GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'");


if (!($row = mysql_fetch_assoc($GetLetters))) {
    $bounce = 1;
}

If ($bounce == 1){

header("Location: letterbox.php");
}
else
{
include("energybarinclude.php");

$row = mysql_fetch_assoc($GetLetters);
$Subject = $row['Subject'];
$From = $row['Sender'];
$SentOn = $row['Senttime'];
$MessageOne = $row['MessageText'];

 

Also just to add if i blank out //$row = mysql_fetch_assoc($GetLetters);

for some reason it won't show row 1 when it should yet it shows row 2 when i do include $row = mysql_fetch_assoc($GetLetters);

How could this be, because row 1 is deffinatly visible in my database.

Link to comment
Share on other sites

$sql = "SELECT * FROM `table` WHERE `this`='that'";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) == 0){ $bounce = 1; }

if($bounce === 1){
header("Location: thisorthat.php");
}else {
$row = mysql_fetch_assoc($res);
//etc...
}

Link to comment
Share on other sites

could you talk me through that i've not seen it written in that way before... just curious i like to understand it as much as get it working :)

 

Edit :

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1
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.