user3008755 user3008755 - 2 years ago 142
MySQL Question

How to loop the query in this case?

I have been trying to loop this query but all I get is the first value.

When I do the same command in workbench I get all the values.
What am I doing wrong here? Any answers are much appreciated!

global $db;
$stmt12 = $db->query('SELECT `Value` FROM overriddenpropertyvalues WHERE ParentGUID LIKE "' . $itemguid . '";');
$propertyvaluerow = $stmt12->fetch();
while ($propertyvaluerow != null) {

Answer Source

You are fetching only one value with ->fetch(). That's why you receive only one value.

Example from here:

$query = $db->prepare('SELECT `Value` FROM `overriddenpropertyvalues` WHERE ParentGUID LIKE :like');

$query->execute([':like' => $itemguid]);


while ($query->fetch()) {
    echo $value."<br/>"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download