title: get previous next row using PDO to create links
body: <p>i've got some bad sytax in my query where i'm trying to create 'prev_id' to pull into the $row result link. any ideas on a better way of doing this? </p>
  
  <p>edit: the error is "Check the manual that corresponds to your MySQL server version for the right syntax to use near 'prev_id'."</p>
  
  <pre><code>function traversePhoto($the_selected_id) {
  global $pdo;
  
  $id = $the_selected_id;
  
  $stmt_a = $pdo-&gt;prepare("
      (SELECT * FROM images WHERE id &lt; '.intval($id).' ORDER BY id DESC LIMIT 1)
       UNION (SELECT * FROM images WHERE id = (SELECT MAX(id) FROM images)) LIMIT 1 prev_id");
  $stmt_b = $pdo-&gt;prepare("
      (SELECT * FROM images WHERE id &gt; '.intval($id).' ORDER BY id ASC LIMIT 1)
       UNION (SELECT * FROM images WHERE id = (SELECT MIN(id) FROM images)) LIMIT 1 next_id");
  
  // $vars = array(':id' =&gt; $id);
  $prev = $stmt_a-&gt;execute();
  $next = $stmt_b-&gt;execute();
  
  if ($prev) {
      while($row = $stmt_a-&gt;fetchObject()) {
          echo '&lt;a href="' . $row['prev_id'] . '"&gt;Previous&lt;/a&gt;';
      } 
  } else {
      echo 'no previous';
  }
  
  if ($next) {
      while($row = $stmt_b-&gt;fetchObject()) {
          echo '&lt;a href="' . $row['next_id'] . '"&gt;Next&lt;/a&gt;';
      }
  } else {
      echo 'no next';
  }
  </code></pre>
  
  <p>}</p>