title: mySQLi query producing null values although query works outside of function
body: <p>This one's driving me round the bend, and just can't work it out. The script works fine up until when I try to echo the final mysqli query (zen_id). I have tested the query outside of the if and while statements and it works fine. The query before it also has no troubles retrieving <code>$model_array['model']</code> and echoes it flawlessly. I don't get any errors, simply nothing is outputted. A vardump of <code>$id_array['zen_system_id']</code> gives me null, as does <code>$id_array</code>, <code>$result_2</code> also produces a large number of null values in this format: <code>object(mysqli_result)#5 (5) { ["current_field"]=&gt; int(0) ["field_count"]=&gt; int(1) ["lengths"]=&gt; NULL ["num_rows"]=&gt; int(0) ["type"]=&gt; int(0) }</code> I think i'm probably misssing something quite obvious here I'm just lost at the moment, possibly something to do with the while function or something??</p>
  
  <pre><code>//Connect to Database
  $mysqli = mysqli_connect("localhost", "login", "user", "database");
  //Check Connection
  if ($mysqli-&gt;connect_errno) {
      echo "Failed to connect to MySQL: (" . $mysqli-&gt;connect_errno . ") " . $mysqli-&gt;connect_error;
  }
  
  $result_1 = mysqli_query($mysqli,"SELECT `product_id` FROM oc_product");
  
  
  while ($rows_1 = mysqli_fetch_array($result_1))
  { 
  
      $product_id = $rows_1['product_id'];
  
      $result = mysqli_query($mysqli,"SELECT `product_id` FROM `oc_product_option_value` WHERE `product_id`=$product_id");
  
      $rows = mysqli_fetch_array($result);
  
      //echo $product_id . " " . $rows['product_id'] . "&lt;/br&gt;";
  
      if($rows['product_id'] == null) 
      {
  
          $result = mysqli_query($mysqli,"SELECT `model` FROM `oc_product` WHERE `product_id`=$product_id");
          $model_array = mysqli_fetch_array($result);
          $model = $model_array['model'] . "&lt;/br&gt;";
  
          //echo $model;
  
          $result_2 = mysqli_query($mysqli,"SELECT `zen_system_id` FROM `oc_wholesale_link` WHERE `model_id`='" . $model . "'");
          $id_array = mysqli_fetch_array($result_2);
          echo $zen_id = $id_array['zen_system_id'];
      }
  
  }
  </code></pre>