简体   繁体   中英

PHP - How to get all rows from a MySQL Query

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.

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.

  $sqlriz = "Select * FROM `tablename`";


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

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

print_r($res);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM