1

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?

2
  • why are you are json_encode(-ing) this stuff? Commented Jun 29, 2013 at 16:56
  • because I call the same fucntion with javascript in other places so needed the output to be a universal format Commented Jun 29, 2013 at 17:43

1 Answer 1

3

$resultArray[] = array() means to push an empty array onto the $resultArray array. Remove the square brackets.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.