I have an array which is populated from a MySQL query:
if ($result) {
$foundResult = true;
foreach ($result as $row) {
array_push($searchResultAccount,$row->Account);
array_push($searchResultUsername,$row->Username);
array_push($searchResultPassword,$row->Password);
array_push($searchResultCreated,$row->Created);
array_push($searchResultStrength,$row->Strength);
}
} else {
array_push($error,"No results found");
}
Further down in my page, I want to create a table and populate the bootstrap table with the results from the array. However, each cell in the table prints all sets of results for that given field. I suspect I have a problem with my loop logic. I tried changing from a foreach to a for loop but still no luck:
<tbody>
<?php for ($x = 0; $x < sizeof($result); $x++) { ?>
<tr>
<td><?php for ($i = 0; $i < sizeof($searchResultAccount); $i++){echo($searchResultAccount[$i]);}?></td>
<td><?php for ($i = 0; $i < sizeof($searchResultUsername); $i++){echo($searchResultUsername[$i]);}?></td>
<td><?php for ($i = 0; $i < sizeof($searchResultPassword); $i++){echo($searchResultPassword[$i]);}?></td>
<td><?php for ($i = 0; $i < sizeof($searchResultCreated); $i++){echo($searchResultCreated[$i]);}?></td>
<td><p>ExpiresHere</p></td>
<td><?php for ($i = 0; $i < sizeof($searchResultStrength); $i++){echo($searchResultStrength[$i]);}?></td>
</tr>
<?php } ?>
</tbody>
The outcome looks like below:
I have 2 results in the array, and as you can see they're printing together in each cell. Any ideas on where I've went wrong ?
Edit: Full PHP code as from the query string below:
$sql = "SELECT * FROM Accounts WHERE User_ID = :userid AND Account = :account";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':userid',$userid);
$stmt->bindValue(':account',$account);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_CLASS);
if($result) {
$foundResult = true;
foreach($result as $row) {
array_push($searchResultAccount,$row->Account);
array_push($searchResultUsername,$row->Username);
array_push($searchResultPassword,$row->Password);
array_push($searchResultCreated,$row->Created);
array_push($searchResultStrength,$row->Strength);
}
} else {
array_push($error,"No results found");
}

array_walk