I have created a webpage which includes the following php code...
$brandArray = JSON_decode(DatabaseInterface::getBrands(), true);
sort($brandArray);
for ($loop=0; $loop < sizeof($brandArray); $loop++) {
echo "<option>$brandArray[$loop]</option>";
}
the relevant bits of the function DatabaseInterface::getBrands are here...
$query = "SELECT psBrandName from brands";
$result = mysqli_query($con, $query) or die ("Couldn't execute query. ".mysqli_error($con));
$resultArray[] = array();
while ($row = mysqli_fetch_assoc($result)) {
extract($row);
$resultArray[] = $psBrandName;
}
return json_Encode($resultArray);
Everything is working fine, except, bizarrely, when I look at the outputs on the webpage, the first item in the list is the word 'Array' (which isnt in the database. Any ideas?
$resultArray[] = array()
means to push an empty array onto the $resultArray
array. Remove the square brackets.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.