title: Cannot cast string to int (php)
body: <p>I am trying to finish my question of the day script.  I have a random number generator (external) which is inserted into a table daily.  I take that number and pull the corresponding question from another table.</p>
  
  <pre><code>// Query 1
  $query1 = "SELECT $field1 FROM $table1 WHERE id=1";
  $result1 = mysqli_query($con1, $query1);
  
  // Query 2
  $query2 = "SELECT $field2 FROM $table2 WHERE QNum = $result1";
  $result2 = mysqli_query($con2, $query2);
  
  // Display question
  while($row = mysqli_fetch_array($result2)) {
      echo $row['question'];
  }
  </code></pre>
  
  <p><code>$result1</code> is pulling a random number, lets say its 9.  When <code>$result1</code> is used to pull the question, it doesn't work but when I replace <code>$result1</code> with number 9, it works.  I experimented with syntax and eventually figured it could be a problem with a string vice an integer.  </p>
  
  <p>I tried to cast it as an integer but it keeps assigning the value of <code>$result1</code> to 1.  I am at a loss.  I don't understand if the string is a 9, how converting it to an integer would change its value.  </p>
  
  <p>I feel like I've tried everything after days of experimenting out there but I am sure it is something very simple.  Please help.</p>