Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:33:35+00:00 2026-06-07T15:33:35+00:00

I am wanting to alter the following php code so that it resizes and

  • 0

I am wanting to alter the following php code so that it resizes and displays images one at a time, with a ‘next’ and ‘previous’ button, in order to browse through the photos. I don’t want any image gallery or lightbox solutions, rather the photos to just show on the page. I’m new to php so If someone can help out or point me in the right direction all help is appreciated.

$sql = "select * from people";
$result = mysql_query($sql) or die ("Could not access DB: " .  mysql_error());
while ($row = mysql_fetch_assoc($result))
{
    echo "<div class=\"picture\">";
    echo "<p>";

// Note that we are building our src string using the filename from the database
    echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br />";
    echo $row['fname'] . " " . $row['lname'] . "<br />";
    echo "</p>";
    echo "</div>";

source of above code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:33:38+00:00Added an answer on June 7, 2026 at 3:33 pm

    You can scale them in the browser using width and height attributes (or just one will maintain aspect ratio) however this is bad for many reasons including bandwidth, page performance and image quality.

    You can re-size the images using libraries such as GD or Imagick

    A quick sample with IMagick:

    $hThumb = new Imagick($path_to_file); // Source file
    $hThumb->thumbnailImage($x, $y); // You can use 300, 0 to do 300 width and maintain aspect ratio.
    $hThumb->stripImage();  // remove meta data
    $hThumb->writeImage($path_to_thumb); // write the image to disk
    

    Note

    Be sure to have permissions to read/write. You can verify this permissions by using is_readable and is_writable.

    Loading

    It’s recommended to load the images using AJAX which is quite easy if using JQuery or a similar library.

    $('#nextBtn').click(function() {
        var index = 0; // Store this in your image ID tag perhaps
                       // e.g. $('#theImage').attr('id').replace('image', '')
                       // where ID is imageX
        $.ajax({
           url: 'getImages.php?index=' + index,
           type: "GET",
           success: function(data) {
               var result = $.parseJSON(data);
               if (result.success) {
                  // Set your image src with the new path. 
                  // Use result.image_data.src etc...
               }
           }
        });
    });
    

    The PHP would be relatively simple too, a structure similar to this:

     <?php
        $return = array('success' => false, 'image_data' => array());
        if (isset($_GET['index']) && is_numeric($_GET['index')) {
           // Fetch your image
           $return = array(
               'success' => true,
               'image_data' => array(
                  'src' => $src, 
                  'title' => $title,
                  'index' => $index
               )
            );
    
        }
    
        echo json_encode($return);
     ?>
    

    ** Another note **

    As stated by kgb you should resize these on upload, however, they may not be user submitted so you can also check if the thumbs exist on output and generate any as required. Certainly don’t generate them for every view though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wanting to display one list element at a time. Ideally, the first
Thanks to the help in a previous question , I've got the following code
I have the following code that closes an iframe footer pop-up I have. <a
I'm wanting to extract a zip file loaded with images into memory in some
I'm wanting to use a php variable as the destination email for Amazon SES
I'm using Iirf v2.0 . I have the following directory structure: / /library /library/index.php
I have the following piece of code: function checkAmount() { var PayField = document.getElementById('paymentamount');
Consider the following code :- public class UsingWait1{ public static void main(String... aaa){ CalculateSeries
I am wanting to create a stored procedure that accepts the team name and
I've got an array of objects that I'm wanting to sort through according to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.