I made a simple PHP script that uploads images to a folder "images" then posts the name of the image to a database "images_db" in a table "images". The table has four columns "id, title, ip, link". I need to make another simple PHP script that would display images in a page with a "Previous" and "Next" link. Any help would be appreciated. Thank you in Advance.
A remember a time when we used to ask questions on Dp, and before we refresh the page we get a dozen answers to the question. I miss the old days
Your question is not clear to me. Do you want to know how to add data in database or you want to know how to get the data form database & display the image or You want a previous or next button. If you want all, then i can't help you because it's a long process, I recommend you to do some Google.
I already made the script that puts the images links in the Database, What I want is to display one image per page, and have a next and previous button to navigate through the pages. Please let me know if you need more information. Thank you so much
$q = mysqli_query($conn,"SELECT * FROM mytable"); $r = mysqli_fetch_array($q); echo '<img src="http://www.myurl.com/images/'.$r['title'].'.jpg'" alt="'.$r['title'].'">'; $idNext = $r['id'] + 1; echo'<a href="?next='.$idNext.'">next</a>'; Code (markup): Then simply for the next image do a $_GET['next'] and get the correct data from mysql to populate the next;
I think this code will help you (Read the program Carefully) <?php include 'mysql_connect.php';//include your mysql_connect file $page_name = 'test.php';//your page name, where you want to display the image if(isset($_GET['page']) && !empty($_GET['page']) && is_numeric($_GET['page'])) { $page = $_GET['page']; if($page == 0) { $page = 1; } } else { header('location:'.$page_name.'?page=1'); exit(); } $table_name = 'image';//your database table name $per_page_image = 1;//set the number of image you want to display per page $start = ($page - 1) * $per_page_image; $next_page = $page + 1; $pervious_page = $page - 1; //get the data form database $query = "SELECT * FROM $table_name"; $result = mysql_query($query); $total_image = mysql_num_rows($result); $query1 = "SELECT * FROM $table_name ORDER BY id DESC LIMIT $page, $per_page_image"; $result1 = mysql_query($query1); while($row = mysql_fetch_array($result1)) { echo '<div align="center">'; echo '<image src="http://yourpageurl.com/image_upload_dir/'.$row['image_name'].'">'; echo '</div>'; } echo '<div align="center">'; if($page <= 1) { echo '<a href="'.$page_name.'?page='.$next_page.'"><input type="button" value="Next"></a>'; } else if($page > 1 && $page < $total_image) { echo '<a href="'.$page_name.'?page='.$pervious_page.'"><input type="button" value="Previous Page"></a>'; echo '<a href="'.$page_name.'?page='.$next_page.'"><input type="button" value="Next"></a>'; } else if($page == $total_image) { echo '<a href="'.$page_name.'?page='.$pervious_page.'"><input type="button" value="Previous Page"></a>'; } echo '</div>'; ?> PHP: In PHP, if you don't understand anything then 'echo' it. You will get your Ans. If any problem then tell me.