1

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 :)

Community
  • 1
  • 1
Space
  • 23
  • 4
  • Are you wanting to cycle through the actual images or just thumbnails? - and how many images are there? – Strawberry Oct 10 '13 at 15:42
  • 1
    [Please, don't use mysql_* functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) in new code. They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about prepared statements instead, and use [pdo](https://wiki.php.net/rfc/mysql_deprecation) or [mysqli](http://stackoverflow.com/questions/tagged/mysqli). – zessx Oct 10 '13 at 15:48

1 Answers1

0

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.

gh123man
  • 1,372
  • 1
  • 14
  • 24
  • @Strawberry, I wanting to cycle through the actual images, there is only 7 images. – Space Oct 10 '13 at 17:05
  • if i add the query you have given me how can i get the next button to work? The id field is the primary key it is auto incrementing. – Space Oct 10 '13 at 17:07