1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Displaying images from a database

Discussion in 'PHP' started by rhoula, Jul 6, 2013.

  1. #1
    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.
     
    rhoula, Jul 6, 2013 IP
  2. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #2
    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 :(
     
    rhoula, Jul 6, 2013 IP
  3. abhijitnumber1

    abhijitnumber1 Member

    Messages:
    19
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    38
    #3
    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.
     
    abhijitnumber1, Jul 8, 2013 IP
  4. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #4
    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
     
    rhoula, Jul 8, 2013 IP
  5. EmmanuelFlossie

    EmmanuelFlossie Active Member

    Messages:
    159
    Likes Received:
    11
    Best Answers:
    2
    Trophy Points:
    65
    #5
    
    $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;
     
    EmmanuelFlossie, Jul 9, 2013 IP
    rhoula likes this.
  6. abhijitnumber1

    abhijitnumber1 Member

    Messages:
    19
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    38
    #6
    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.
     
    abhijitnumber1, Jul 10, 2013 IP
    rhoula likes this.
  7. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #7
    Thank you so much, I will try it and see how it works.
     
    rhoula, Jul 10, 2013 IP
  8. uniphoresolution

    uniphoresolution Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    Voice Biometrics

    Abhijit thanks for helping me i will try this code in project.
     
    uniphoresolution, Jul 11, 2013 IP
  9. abhijitnumber1

    abhijitnumber1 Member

    Messages:
    19
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    38
    #9
    Happy To Help
     
    abhijitnumber1, Jul 11, 2013 IP