Is is possible to loop two times through a result from a pdo query ? the first function is to get the query results
function querySelectBrand($pdo)
{
$table01 = 'brand';
$table02 = 'text';
$querySelectBrand="SELECT $table01.*,
textDef.$table02 as defText,
textUsr.$table02 as usrText
FROM $table01
LEFT JOIN $table02 as textDef on $table01.textId = textDef.textId And textDef.languageId = $_SESSION[defaultLanguage]
LEFT JOIN $table02 as textUsr on $table01.textId = textUsr.textId And textUsr.languageId = $_SESSION[defaultLanguage];";
// echo $querySelectBrand;
$stmt = $pdo->prepare($querySelectBrand);
$stmt->execute([]);
return $stmt;
}
then I pass the $stmt as $result to a function to build a drop down box.
function dropDownBox($result, $name, $size, $selected)
{
$x=1;
echo'<select name="'.$name.'" size="'.$size.'">';
foreach($result AS $row01){
$id=$row01['id'];
if(isset($row01['usrText'])){$text=$row01['usrText']; }else{$text=$row01['defText']; }
if(isset($selected)and $id==$selected){
echo '<option value="'.$id.'" selected>';
echo $text;
echo '</option>';
}else{
echo '<option value="'.$id.'">';
echo $text;
echo '</option>';
}
}
echo'</select>';
reset($result);
foreach($result AS $row01){
$x++;
}
?>
<input type="text" name="testresult" value="<?php echo $x; ?>">
<?php
}
How can I make the second foreach loop go through the $result again ? the output from $x is now 1.
reset($result);
does not work.