1

This is my code:

if($login_check > 0) {
    $results = mysql_query("SELECT * FROM messageInfo WHERE senderUsername='$username' UNION ALL SELECT * FROM messageInfo WHERE recieverUsername='$username';");
    var_dump(mysql_fetch_assoc($results));

}

I'm getting only one row "var_dumped", when I should be getting two rows returned.

2
  • 4
    Heads up! Future versions of PHP are deprecating and removing the mysql_ family of functions. Now would be a great time to switch to PDO or mysqli. Commented Dec 9, 2012 at 8:39
  • 2
    Also, please refrain from drastically rewriting a question as to make it entirely different. You have basically invalidated a set of previously given answers and wasted a great deal of time. It's poor form at best, and editors crankier than myself may choose to revert your massive rewrite. Commented Dec 9, 2012 at 8:41

2 Answers 2

9

Try following code:

$result = mysql_query("SELECT * FROM messageInfo WHERE senderUsername='$username' OR recieverUsername='$username'");

while ($row = mysql_fetch_assoc($result)) {
    print_r($row);
}

I think that UNION is not really needed in this query, OR statement would be just enough.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you sir! You have solved an hours work. The reason ours wasn't working was because var_dump stopped the PHP script. I feel stupid
0
  $sqlriz = "Select * FROM `tablename`";


    $Rslt = mysqli_query($Conn,$sqlriz);

    while($r=mysqli_fetch_object($Rslt))
    {
        $res[]=$r;
    }

print_r($res);

1 Comment

Can you try and enhance the formatting and add some explanation what the key points are?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.