简体   繁体   中英

php sql query changes url, however doesn't change data

I'm trying to make a "next button" for my database, so i can view one image at a time. However the way i have it right now only changes the url and not actually the image check it out here. It sticks to the image with the highest id on it (87) no matter what the url is. How do i fix this?

this is how my db looks

在此输入图像描述

<?php 
require("includes/conn.php");

if (isset($_GET["imagecount"]))
$next = (int)$_GET["imagecount"]; //int is for sql injection 
else
    $next = 0;

$result = mysql_query("select * from people order by id desc limit $next, 1") or die(mysql_error());


?>



        <?php


            $result = mysql_query("select * from people order by id desc limit 0, 1 ") or die ("haznot DB: " . mysql_error());

            while ($row = mysql_fetch_assoc($result))
            {

                echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br />";
            }

        ?>

<a href="images.php?imagecount=<?php echo $next+1; ?>">Next</a>     

You want WHERE id = $next in your query. Not what you have.

Why do you have two mysql queries...

"Select * FROM people WHERE `id` = $next"

You should select WHERE id=$next . You seem to have fewer than 87 images present, so the limit clause won't behave as you expect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM