I'm learning PHP and MySQL, just trying to understand stuff right now.
Tried googling this, couldn't find anything on it, or I was looking in the wrong places.
This is my code:
<?php
$mysqli = new mysqli("localhost", "root", "fakepassword", "fakedbname");
$result = $mysqli->query("SELECT * FROM testtable");
$datas = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$datas[] = $row;
}
}
foreach ($datas[0] as $data) {
echo $data . "<br>";
}
?>
<?php mysqli_free_result($result);
?>
This is what I see when I refresh the page:
So, to debug it, I entered:
<pre>
<?php print_r($datas);?>
</pre>
Then it shows me:
On PHPMyAdmin, I see this:
If it helps, I manually queried the data into the table using
CREATE TABLE testtable (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
A VARCHAR(30) NOT NULL,
B VARCHAR(30) NOT NULL,
C VARCHAR(30) NOT NULL)
and,
INSERT INTO testtable (A, B, C)
VALUES ('Hi', 'There', 'Mark')
What's wrong? Why does it repeat itself?