Incrementing through mysql PHP

Posted by Rawdon on Stack Overflow See other posts from Stack Overflow or by Rawdon
Published on 2014-08-19T10:05:20Z Indexed on 2014/08/19 10:20 UTC
Read the original article Hit count: 139

Filed under:
|
|

I am looking at try to increment and decrement by three records through a table and present those records. Say if the id '4' is currently active. I want the to be display the ID's and category of 3.2.1 and 5.6.7 from an increment and decrement

So far I have:

$stmt = $db->query("SELECT id, category FROM test");
$stmt->execute();

while ($results = $stmt->fetch(PDO::FETCH_ASSOC))
{
  $current = $results['id'];
  $category = $results['category'];
  $next = array(array('slide_no' => $current, 'category' => $category));
}
print_r($next);

Now with this, I am getting back every row in the table.

I'm now getting confused on how I could increment and decrement the records by 3 and make sure that the category will also increment correctly.

Thank you very much.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql