PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$imgtype = $_GET['imgtype'];
$cnt = $_GET['cnt'];
if (!isset($cnt)) {
$cnt = 0;
}
//select proper row in table based on cnt.
$sql = "SELECT * FROM `test` WHERE `imgtype` = '$imgtype'";
$sql .= " LIMIT $cnt, 1";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$imgid = $row['ImgId'];
$imgname = $row['ImgName'];
The table is populated by Image names, types, and location. As you can see I am grabing all the records by $imgtype, then selecting one at a time based on the $cnt. Every time the page is reloaded the $cnt increments by one, so it should select the next row in the table based on the $imgtype and $cnt.
My problem is that even though I should be selecting only the records with the correct $imgtype. Its not, its selecting all the records in the table, even the ones with a different $imgtype.
The table is populated by Image names, types, and location. As you can see I am grabing all the records by $imgtype, then selecting one at a time based on the $cnt. Every time the page is reloaded the $cnt increments by one, so it should select the next row in the table based on the $imgtype and $cnt.
Actually, the code that you have posted doesn't do what you're telling here...
My problem is that even though I should be selecting only the records with the correct $imgtype. Its not, its selecting all the records in the table, even the ones with a different $imgtype.
My advise is to echo the query before you use it... The query appears to be valid syntax and should do (more or less) what you described. The rows in a resultset aren't ordered unless you use an ORDER BY clause per definition.
I hope for you that you don't have any evil users... Or that you didn't post the code where you validate the input.
Anyway, clicking next and previous will show you the pictures in the table based on the $imgtype. The pictures that are broken should not even be showing up, they have a different $imgtype.
You can see that in my echo of the sql query. There is 3 flagstone pictures and 6 brick pictures.