I am wanting to add buttons that will allow the user to cycle through images i have stored in my database. A next and previous button.
I have found this post but do not understand it.
best way for next/previous buttons for entries in yii
Here is a link to the page.
http://www.colourmyiphone.co.uk/phone.php
Function code, db_connect has the database stored and is working. The function is being called from the phone.php page.
<?php
include 'db_connect.php';
function show_body(){
$product = mysql_query("SELECT COUNT(id), colour, link FROM phone_body") or die(mysql_error());
$row = mysql_fetch_array($product);
$count = $row['COUNT(id)'];
$colour = $row['colour'];
$link = $row['link'];
//echo "$count";
echo "<img class=\"phone\" img src=$link> </br>";
echo "<form action=\"\" method=\"POST\">
<input type=\"submit\" name=\"next\" class=\"next\" value=\"Next\">
</form>";
echo "<form action=\"\" method=\"POST\">
<input type=\"submit\" name=\"previous\" class=\"previous\" value=\"Previous\">
</form>";
}
?>
Thanks for the help :)
You need to select the "current" item to be displayed and the "next" item to be displayed. This is dependent on how your data model looks. If your images are stored with incrementing ids, you can do something like
"SELECT id FROM phone_body where id >= $currentID limit 2 order by id asc"
That should give you the current ID and the next ID assuming your ids are ordered.
To get to the next image, just plug the "next" id into the "current" id position.