$category = array(
"Alpha",
"Beta",
"Gamma",
"Delta",
"Epsilon",
"Zeta"
);
for ($count = 0; $count < 5; $count++) {
$query = "SELECT * FROM random_walk WHERE category = '$category[$count]'";
$result = $mysqli->query($query) or die($mysqli->error . __LINE__);
$row_cnt = $result->num_rows;
if ($result->num_rows > 0) {
$row_counter = 0;
while ($row = $result->fetch_assoc()) {
$category[$count][$row_counter] = $row['image_filename'];
$row_counter++;
echo $category[$count][$row_counter];
}
}
}
I am trying to store MySQLi $row data into a PHP 2 dimensional array $category[][]
.
I have initialized an array named $category
which contains contains the category names I wish to use. I now want to retrieve records from my database and store the contents of the record field image_file
(eg. poly_interpolated.jpg) into the second dimension and loop until there are no more images files for that category in the database.
However, when I echo the array I only see a single character which is not what I was expecting to happen at all as $row['image_file'
] returns a filename of multiple characters in length.
I would have thought that $category[$count][$row_counter] = $row['image_filename'];
would store the name of the file but it appears I'm some way off in that assumption.
Can someone please take a look at the above code and point me in the right direction?
$category
, is this intentional? I feel this will cause a lot of errors since you're already using the exact name for the loop. – Dave Chen Jun 10 at 1:01