Reputation: 49
I'm trying to create a single dimensional enumerated array of a single column of data.
$dbc_db_filenames = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$query_db_filenames = "SELECT file FROM transactions_tb WHERE file != ''";
$get_db_filenames = mysqli_query($dbc_db_filenames, $query_db_filenames);
$array_rows = array();
while($rows = mysqli_fetch_array($get_db_filenames, MYSQLI_NUM)) {
$array_rows = $rows;
echo "<br /><br /><pre>";
print_r($array_rows);
echo "</pre><br />";
}
mysqli_close($dbc_db_filenames);
Currently it's returning multiple arrays like this:
Array
(
[0] => 2_20140908130612381070.jpg
)
Array
(
[0] => 2_20140908131122368017.jpg
)
Array
(
[0] => 2_20140908130449345689.jpg
)
I want it to return an array like this:
Array
(
[0] => 2_20140908130612381070.jpg
[1] => 2_20140908131122368017.jpg
[2] => 2_20140908130449345689.jpg
)
I'm comparing a directories contents with the filename that's stored in the database on upload. To get the directories contents into an array I'm using this code:
$list = scandir(UPLOAD_PATH);
echo '<br /><br /><pre>';
print_r($list);
echo '</pre><br />';
Which returns the kind of array I want:
Array
(
[0] => 2_20140908130612381070.jpg
[1] => 2_20140908131122368017.jpg
[2] => 2_20140908130449345689.jpg
)
Upvotes: 1
Views: 387
Reputation: 118
Have you tried this?
while($rows = mysqli_fetch_array($get_db_filenames, MYSQLI_NUM)) {
$array_rows[] = $rows[0];
}
echo "<pre>";
print_r($array_rows);
echo "</pre>";
Upvotes: 1