php - Navigate throught databse rows -
i run image hosting site, , ive run problem. want make 2 buttons beside pic "next image" , "prev image". im new php/mysql , haveing troubles.
check out got. use id (numbers) find correct row, have image name build next link. how make below query next , prev image names + ids?
$query_next = ("select imageid, image_name images image_name = '$image_main' order imageid desc limit 1"); $query_prev = ("select imageid, image_name images image_name = '$image_main' order imageid asc limit 1"); // next $next = mysql_query($query_next); // prev $prev = mysql_query($query_prev); while ($row = mysql_fetch_assoc($next)) { $next = $row['image_name']; } while ($row = mysql_fetch_assoc($prev)) { $prev = $row['image_name']; }
the html = > simple stuff.
<a href="http://mysite.com/view_image/<?=$next?>">next image</a> <a href="http://mysite.com/view_image/<?=$prev?>"> prev image </a>
for previous item want first row smaller current id:
"select imageid, image_name images imageid < $current_img_id order imageid desc limit 1"
for next item want first row larger current id:
"select imageid, image_name images imageid > $current_img_id order imageid asc limit 1"
Comments
Post a Comment