oha055 Posted October 10, 2011 Share Posted October 10, 2011 Hi! I want the image of my site to be clickable so that it shows the next image contained in the result set of the sql query. <?php require_once('includes/connection.inc.php'); $conn = dbConnect(); $sql = 'SELECT filename FROM images ORDER BY image_id DESC LIMIT 1'; $msg = ''; if(!$sql) { echo "Something went wrong with the query. Please try again."; } $result = $conn->query($sql) or die(mysqli_error()); if(mysqli_num_rows($result) == 0) { header('Location: empty_blog.php'); $conn->close(); } else { $row = $result->fetch_row(); $image = $row[0]; } ?> <?php include('header.php'); ?> <div class="content main"> <img id="image" src="images/<?php echo $image; ?>"/> </div> <?php include('includes/footer.inc.php'); ?> All the filenames of the images are contained correctly in the $result variable, all I need to do now is to fetch the next image in the set. How would I go about this? Any help is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/248790-displaying-images-from-result-set/ Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 Try the following: <?php $imageid = 1; if(isset($_GET['id']) { $imageid = $_GET['id']; } require_once('includes/connection.inc.php'); $conn = dbConnect(); $sql = 'SELECT filename FROM images WHERE image_id = $imageid'; $msg = ''; if(!$sql) { echo "Something went wrong with the query. Please try again."; } $result = $conn->query($sql) or die(mysqli_error()); if(mysqli_num_rows($result) == 0) { header('Location: empty_blog.php'); $conn->close(); } else { $row = $result->fetch_row(); $image = $row[0]; } ?> <?php include('header.php'); ?> <div class="content main"> <a href="thispage.php?id=<?php echo $imageid+1; ?>"> <img id="image" src="images/<?php echo $image; ?>"/> </a> </div> <?php include('includes/footer.inc.php'); ?> I haven't actually tested this so forgive me if I've missed something out. Hopefully you'll get the idea. Quote Link to comment https://forums.phpfreaks.com/topic/248790-displaying-images-from-result-set/#findComment-1277663 Share on other sites More sharing options...
oha055 Posted October 10, 2011 Author Share Posted October 10, 2011 Thank you so much for your reply! I tried out your suggestion, but now I am getting this error: "Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\photoblog\index.php on line 13" On this line: $result = $conn->query($sql) or die(mysqli_error()); Don't know what to make of this, there was no bitching about this before Quote Link to comment https://forums.phpfreaks.com/topic/248790-displaying-images-from-result-set/#findComment-1277682 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 Try $result = $conn->query($sql) or die(mysqli_error($conn)); Quote Link to comment https://forums.phpfreaks.com/topic/248790-displaying-images-from-result-set/#findComment-1277684 Share on other sites More sharing options...
oha055 Posted October 10, 2011 Author Share Posted October 10, 2011 Well, that worked! ....The page displays fine now. Still doesn't jump to the next image in the result set though. When I click on the image, the address bar displays "http://localhost/photoblog/index.php?id=2", but the image doesn't actually change to image no. 2 Thank ou so much anyways Quote Link to comment https://forums.phpfreaks.com/topic/248790-displaying-images-from-result-set/#findComment-1277692 Share on other sites More sharing options...
oha055 Posted October 10, 2011 Author Share Posted October 10, 2011 NEVERMIND! I got it working! You have been of great help! :D It works perfectly now. Quote Link to comment https://forums.phpfreaks.com/topic/248790-displaying-images-from-result-set/#findComment-1277696 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 cool - can you mark this thread as solved for me? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/248790-displaying-images-from-result-set/#findComment-1277698 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.