私は、MySQLのクエリから移入されたアレイがあります。さらに下の私のページでPHPのループは、HTMLテーブルを作成するための
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");
}
が、私はテーブルを作成してからの結果とブートストラップのテーブルを移入したいが配列。ただし、テーブル内の各セルは、そのフィールドのすべての結果セットを出力します。私は私のループロジックに問題があると思う。私は、forループにforeachのから変えてみましたが、まだ運:
<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>
結果は以下のように見えるん:
私は、アレイ内の2つの結果を持って、そしてあなたが見ることができるように彼らは各セルに一緒に印刷しています。私がどこに間違っていたかに関するアイデアは?
編集:
$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");
}
クエリ文字列から完全なPHPコードを投稿できますか? –
なぜ 'array_walk'を使わないのですか –