0

I have a multi-query MySQLi statement that uses multiple queries and when using var_dump brings back the following:

var_dump of array:

array(1) { ["company"]=> string(8) "ffr3e456" ["high_1"]=> string(8) "8.32465" }
array(2) { ["company"]=> string(8) "gg8751hw" ["high_2"]=> string(7) "7.66574" }

The code I am using to display the array in a PHP file picks up the first array (i.e. the content of high_1 information but not the second.

code

if ($mysqli->multi_query($query)) {
    do {
        /* store first result set */
            if ($result = $mysqli->store_result()) {
                while ($row = $result->fetch_assoc()) {
                    for ($p=1; $p<=2; $p++)
                         {
                         echo number_format($row["high_".$p],2);

The HTML output shows the data from the first array but not the second. I am sure I am overlooking something, any advice and feedback welcomed.

5
  • Can you show the code that actually does the query and fetches the results? Commented Jul 1, 2014 at 16:00
  • Your keys have the names high_1 and high_2, not novhigh_1 and novhigh_2. Why don't you get those values with a single UNION statement instead? Commented Jul 1, 2014 at 16:01
  • Added the preceeding code. Adjusted code so high_1 and high_2 match. Can't use UNION on this occasion. Commented Jul 1, 2014 at 16:11
  • And what produces the output that you provided at the top? Certainly not var_dump($row);. Commented Jul 1, 2014 at 16:23
  • @PatrickQ - it is actually a var_dump - for simplicity I've kept the amount of data in the array to two simple items. Commented Jul 1, 2014 at 16:59

2 Answers 2

1
$C = array_merge($A, $B);

You can read more here: http://www.php.net/manual/de/function.array-merge.php

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

3 Comments

Thanks @ssergei - however, both arrays are within the $row variable - no idea how to merge or combine them.
$A = $row[0]; $B = $row[1];
Could you provide a print_r of $row so we could see how the array is constructed?
0

It would be helpful if you showed the SQL statement that returns the results.

Are the returned arrays in separate $row results?

In that case you need to iterate through each $row result, something like:

foreach($query->result() as $row)
{
 for ($p=1; $p<=2; $p++)
 {
  echo number_format($row["novhigh_".$p],2);
 }
}

On a side note: It looks like the key definition inside the arrays is not logical, why not have the same key value for the "novhigh" element?

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.