You're correct, you could use arrays. Depending on how you want to use the data afterwards, there are (at least) two potential structures:
Three separate arrays - one list of image names, one of extensions and one of projects.
A single array containing one entry for each row retrieved from the database, with the fields for that row in an associative array (or object) within that.
In most cases, option 2 is likely to be more useful, since it doesn't de-couple the data from the other data items which belong with it logically. (e.g. it would probably be a bit useless to have the extension but not have the file name which went with it. You could try to match it up via the array index, but then you think - why separate it to begin with?)
So here's an example of how you'd implement option 2. Note the use of mysqli_fetch_assoc
instead of mysqli_fetch_array
, so that you get each row out as an associative array with column names for the keys, instead of just numbers.
$sql = mysqli_query($con,"SELECT imgname FROM images WHERE project='testproject'");
$data = array(); //create an empty array
//loop over all the rows
while ($row = mysqli_fetch_assoc($sql)) {
$data[] = $row; //add the whole row to the array
}
var_dump($data); //debugging output, just so you can see the result
Alternatively you could also use mysqli_fetch_all to simply get all the results into an array at once:
$data = mysqli_fetch_all($sql, MYSQLI_ASSOC);