user3008755 user3008755 - 6 months ago 27
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

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]);

$stmt->bind_result($value);

while ($query->fetch()) {
    echo $value."<br/>"
}
Comments