Get values ​​relative to values ​​in another column

I want to select all custom values ​​where the status is review

(there are four of them :) sky - earth - sea - sun

.

$stmt = $db->query("select user from posts where status = 'review'");
$rows = $stmt->fetch();
foreach ($rows as $row){
    echo $row . '<br>';
}

      

Result:

sky
sky

      

I need:

sky
earth
sea
sun

      

Any help?

+3


source to share


2 answers


Since you are requesting multiple entries. $rows=$stmt->fetch()

will only get one record at a time, so you have to go with a while loop to get each record that matches your encoding.

Try the following:



while ($rows = $stmt->fetch()) {
    echo $rows['user'] . '<br>';
}

      

+2


source


$stmt = $db->query("select user from posts where status = 'review'");
while ($rows = $stmt ->fetch_object()) {
    echo $rows->user . '<br>';
}

      



here's an updated answer

+2


source







All Articles