I'm selecting data from a table that has 1 column, but can have up to 100 rows. Then I take the data and set an associative array with a key of the value of each row, and a value of 1. This lets me just see if it exists later.
The code looks like like this (I tried to simplify it for this post, please forgive any typos):
$query = sprintf("SELECT col FROM table WHERE id=%s",
mysqli_real_escape_string($dbh, $_GET['id']));
$results = mysqli_query($dbh, $query);
if ($results && mysqli_num_rows($results) > 0) {
$arr = [];
while (list($str) = mysqli_fetch_row($results))
$arr[$str] = 1;
}
Is there a way to create this array without going through a while loop?
I thought that this would work:
$arr = mysqli_fetch_assoc($results); but it creates
$arr['col'] = "value", and I think it overwrites each one until $arr['col'] only equals the last value. So it would work if I only had 1 row result, but that's all.