I'm using PDO. I want to be able to fetch 3 values from 3 different rows using a single query. I've got a table as below.
itemID | Item_Name
____________________
125 | apple
297 | Lychee
851 | Mango
005 | Orange
1009 | Strawberry
I want to be able to send an Item_Name
and sort the table by Item_Name
and to be able to call the next Item_Name
and the previous Item_Name
. How can I do this?
e.g.:
if the
$passedItem
isOrange
I want to outputMango
andOrange
andStrawberry
.if the
$passedItem
isMango
I want to outputLychee
andMango
andOrange
Using the on()
operator did not work because only one Item_Name could be passed on to the query.
$sql = "SELECT Item_Name FROM itemsTable WHERE Item_Name = :passedItem" ORDER BY ASC;
$stmt = $con_db->prepare($sql);
$stmt->execute(array(':passedItem'=>"Orange"));
$rslt = $stmt->fetchAll(PDO::FETCH_ASSOC);