Hello there,
I’ve spent the best part of a week trying to get this to work, and scoured the Internet for a solution, and got nowhere, so I’m now desperately hoping someone here can save the day!
What I’ve done is use mysqli_multi_query to SELECT three records from two different MySQL tables. Then I’ve combined the two outputs $output1 and $output2 into one array called $final, by using array_merge.
Everything works fine up to that point.
The last step is to display the contents of the $final array, but nothing I’ve tried works, every variation of code I’ve tried just displays the word Array instead of the actual value. Yet I know the values are sitting in the array, through checking the output of the print_r function (as below).
The only suggestion I found on Google that looked like it might work, was to assign the value of each array element to a string variable first, and then echo that … but all that did was assign the value Array to the string … again!
I’m completely stumped by this, so any ideas on how to output the actual values would be vastly appreciated! The relevent section of code is below (everything up to this point works fine, just this final step is the unsolvable problem for me).
<?php
$final=array_merge($output1,$output2);
$total_rows = $count_rows_1 + $count_rows_2;
$i = 0;
while ($i <= $total_rows) {
print_r($final[$i]);
echo '<li>',$final[$i],'</li>';
$i++;}
?>
From what I’ve read, the blank line in the output below is due to a gremlin with PHP’s mysqli_multi_query, that generates an unwanted extra record.
[COLOR=“#FF8C00”]/* OUTPUT
Array ( [0] => blue dalek [1] => (reviewer) )
Array
Array ( [0] => bluemoon [1] => (reviewer) )
Array
Array ( [0] => bubbleboy [1] => (reviewer) )
Array
Array ( [0] => beatles IV [1] => (album) )
Array
Array ( [0] => blue aeroplanes [1] => (album) )
Array
Array ( [0] => bluemoon [1] => (album) )
Array
*/[/COLOR]
Not sure if it’s relevent, but the background to this is that it’s part of an Autocomplete Search function, which involves jQuery (that’s why all the records begin with ‘b’, to test Autocomplete). Normally, Autocomplete can only query one table, so what I’ve done is use mySQLi’s multi-query function to query two tables, then merged the two results into one array, then applied Autocomplete to that … it’s working fine, except I don’t see the values in my search results, just this darned Array! Maybe I broke jQuery somehow …?