0

What seems to be happening is $result_tag is only holding the first row of the sql data retrieved.

When I run the result query on SQl in returns a table with multiple rows. However, when I var_dump() it, it only returns the first row and nothing else.

  while($row = $results->fetch_array(MYSQLI_BOTH)) {    
  echo ....stuff that dont matter

  //Now I want some SQL results based on a result from ^^^ $row['ID']
  $result = $conn->query("SELECT tags.Tag FROM tags WHERE tags.results_ID =".$row['ID'] );
  $result_tag = $result->fetch_array(MYSQLI_NUM); 

  //I got the results. Now I want to compare them to another array '$explode' 
  //and echo out elements that are the same

    foreach($explode as $explodeValue){
      foreach($result_tag as $tag){
        if($tag == $explodeValue){
          echo $explodeValue;
        }
      }
    }

}//end of 1st while

2 Answers 2

1

You want to use fetch_all(); fetch_array() returns just one row (as an array) See http://php.net/manual/en/mysqli-result.fetch-all.php

This is in fact what the outermost while is doing, fetching one row at a time with fetch_array()

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

Comments

1

Change to

$result = $conn->query("SELECT * FROM tags WHERE results_ID =".$row['ID'] );

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.