title: Running two separate SQL queries on one php page
body: <p>I've manage to find lots of answers for merging SQL queries of multiple tables but I'm a newbie and want to run two completely separate queries on two different tables and display the results on a single .php page.</p>
  
  <p>Unfortunately I receive a "<strong>Notice: Undefined index:</strong>" error. So I guess, my question is, how do I define an index on the first or second query to avoid the error?</p>
  
  <p>Query 1 displays info from a table containing sightings data, the second query is to display a list of news items on the same .php page.</p>
  
  <p>Sorry if this is a stupid question but I'm very new to PHP and SQL... but you can already tell that!</p>
  
  <p>Huge thanks for any help, it will be very much appreciated!!</p>
  
  <p>Cheers</p>
  
  <p>Steve</p>
  
  <hr>
  
  <p>Heres' my SQL:</p>
  
  <pre><code>&lt;?php require_once('inc/connection.php');?&gt;
  
      &lt;?php
      // connect to MySQL
      $conn = dbConnect('read', 'pdo');
      // prepare the SQL query
      $sql = "SELECT * FROM wbcsightings WHERE spYear = year(curdate()) AND spFirstDate IS NOT NULL";
      $wbcsightings = $conn-&gt;query($sql);
      $error = $conn-&gt;errorInfo();
      if (isset($error[2])) die($error[2]);
      $numRows = $wbcsightings-&gt;fetchColumn();
      $wbcsightings-&gt;closeCursor();
      ?&gt;
  
      &lt;?php
      // connect to MySQL
      $conn = dbConnect('read', 'pdo');
      // prepare the SQL query
      $sql = 'SELECT * FROM wbcnews WHERE newsDisplay="yes" ORDER BY newsDate desc';
      $wbcnews = $conn-&gt;query($sql);
      $error = $conn-&gt;errorInfo();
      if (isset($error[2])) die($error[2]);
      $numRows = $wbcnews-&gt;fetchColumn();
      $wbcnews-&gt;closeCursor();
      ?&gt;
  </code></pre>
  
  <p>And here's the code I'm using to display the results of the first query (table wbcsightings)</p>
  
  <pre><code>&lt;?php $i=0; foreach ($conn-&gt;query($sql) as $row) { if($i==3) break;?&gt;
  &lt;?php echo $row['spName']; ?&gt;
  &lt;?php echo $row['spFirstDate']; ?&gt;
  &lt;?php echo $row['spLocation']; ?&gt;
  &lt;?php echo $row['spRecorder']; ?&gt;
  &lt;?php $i++;} ?&gt;
  </code></pre>
  
  <p>And the code to display the results of the second query (table wbcnews)</p>
  
  <pre><code>&lt;?php $i=0; foreach ($conn-&gt;query($sql) as $row) { if($i==3) break;?&gt;
  &lt;?php echo $row['newsTitle']; ?&gt;
  &lt;?php echo $row['newsDate']; ?&gt;
  &lt;?php echo $row['newsSubTitle']; ?&gt;
  &lt;?php echo $row['newsAuthor']; ?&gt;
  &lt;?php $i++;} ?&gt;
  </code></pre>