I have a MySQL table:
id header content
-------------------------
10 test3 <p>test</p>
9 test2 <p>test</p>
8 test <p>test</p>
but when I run this code:
$sql = "SELECT * FROM posts";
$query = mysqli_query($db_conx, $sql);
if($query) {
$row = mysqli_fetch_row($query);
for($i; $i < count($row); $i++){
echo $row[$i] . " ";
}
}
it only selects the first row.
My ideal output would by an array that looks like:
$dataArray[0][0] = "10"
$dataArray[0][1] = "test3"
$dataArray[0][2] = "<p>test</p>"
$dataArray[1][0] = "9"
$dataArray[1][1] = "test2"
$dataArray[1][2] = "<p>test</p>"
$dataArray[2][0] = "8"
$dataArray[2][1] = "test"
$dataArray[2][2] = "<p>test</p>"
etc;
What is the correct way to select multiple rows?
fetch_row()does exactly what its name suggests: it fetches a single ROW. You're looping on the individual fields in that row.