Closed Thread
Page 18 of 22 FirstFirst ... 81617181920 ... LastLast
Results 171 to 180 of 214

Thread: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

  1. #171
    Astha is offline Newbie
    Join Date
    Aug 2010
    Posts
    25
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hello Jaan,


    I got a similar script, it displays the image, but I have to reference the individual images (by its id, i.e, testgetpicture.php?image_id=1) separately. Is there any way where I can display all the images (from database table) in a row or column without specifying a specific id?



    Here's my script:
    testgetpicture.php
    Code:
    <?php
        
    // just so we know it is broken
        
    error_reporting(E_ALL);
        
    // some basic sanity checks
        
    if(isset($_GET['image_id']) && is_numeric($_GET['image_id'])) {
            
    //connect to the db
            
    $link mysql_connect("localhost""root""") or die("Could not connect: " mysql_error());
     
            
    // select our database
            
    mysql_select_db("templetree") or die(mysql_error());
     
            
    // get the image from the db

            
    $sql "SELECT content FROM sample_design WHERE image_id=".$_GET['image_id'];
     
            
    // the result of the query
            
    $result mysql_query("$sql") or die("Invalid query: " mysql_error());
     
            
    // set the header for the image
            
    header("Content-type: image/jpeg");
            echo 
    mysql_result($result0);
     
            
    // close the db link
            
    mysql_close($link);
        }
        else {
            echo 
    'Please use a real id number';
        }
    ?>

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #172
    pravin3009 is offline Newbie
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hi Astha,

    where r u showing the image, is it html image control or anything else? can you share those few lines too....

    Thanks
    -pravin

  4. #173
    Astha is offline Newbie
    Join Date
    Aug 2010
    Posts
    25
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hi,

    Yes, you have to display the image in another file (html/php).

    Here's the code:
    display_image.html
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    </head>
    <body>
    <img src="testgetpicture1.php?image_id=1"  />
    </body>
    </html>
    But make sure that this HTML page (display_image.html) should be in the same folder where your testgetpicture.php file is.

    Hope this helps you and let me know.

  5. #174
    pravin3009 is offline Newbie
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Thank you Astha,

    unfortunatly that did not work, here is my code, what I am getting a is box with cross mark-
    Code:
    //php code
    //getImage
    <?php 

    mysql_connect
    ("localhost:3306","root","mysql2010") or die("Unable to connect to SQL server"); 
    @
    mysql_select_db("testdb") or die("Unable to select database"); 
    $result=mysql_query("select * from tblimagedetails where rowid=1") or die("Can't perform Query"); 

    $data=@MYSQL_RESULT($result,0,"data"); 
    header('Content-type: image/jpg'); 
    echo(
    $data);  

    ?>
    Code:
    //html code - the place where I am calling getimage is at the bottom, as you suggested so I tried 
    //to keep the image call in the body element, rather than a <td> element as I wanted to...

    <html>
     <
    head>
      <
    style type="text/css">
       .
    background background-image:url(back.png);background-repeat:repeat-x; }
    </
    style>
      <
    title>PHP Test</title>
     </
    head>
     <
    body>
     <
    div class="background">
      <
    table style="width:100%; height:100px;">
         <
    tr>
           <
    td width="100%" align="center" height="100px">
            <!-- 
    Banner -->
             
    My Page
          
    </td>
        </
    tr>
       </
    table>
        <
    table style="width:100%; height:100px;">
         <
    tr>
           <
    td>
             <!-- 
    Image1   --> 
                    
             
           </
    td >
           <
    td width="30%" style="height:100px;">
             <!-- 
    Image2 -->        
           </
    td>
           <
    td width="30%" style="height:100px;">
             <!-- 
    Image3 -->
             
    image 3
           
    </td>
         </
    tr>
         </
    table>
      </
    div>
       <
    img src="getImage.php" >   
     </
    body>
    </
    html
    If you think, there are some environment settings required related to php or IIS let me know.
    Last edited by Orjan; 08-07-2010 at 01:42 PM.

  6. #175
    Prog4rammer's Avatar
    Prog4rammer is offline Newbie
    Join Date
    Jan 2010
    Location
    Gaza
    Posts
    14
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Thanks a lot very Cool

    Some Words Me : "♪●Software Engineer and Love Programming in Java and PHP under Ubuntu System ... ♪♥ "

  7. #176
    sundayose is offline Newbie
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Thanks for your thread.
    Help me with my code below on how to display an image from Mysql (longblob) in the picture field.
    This code is the results page for my search page with search parameter. The problem I have is that when I search, the results page has funny staff in the picture field.
    Thank you.

    Code:
    <?php require_once('Connections/conn_hostels.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    $colname_rsEresults = "-1";
    if (isset($_POST['hostel_name'])) {
      $colname_rsEresults = $_POST['hostel_name'];
    }
    $colname2_rsEresults = "-1";
    if (isset($_POST['institution_nearest'])) {
      $colname2_rsEresults = $_POST['institution_nearest'];
    }
    $colname3_rsEresults = "-1";
    if (isset($_POST['category'])) {
      $colname3_rsEresults = $_POST['category'];
    }
    $colname4_rsEresults = "-1";
    if (isset($_POST['district'])) {
      $colname4_rsEresults = $_POST['district'];
    }
    mysql_select_db($database_conn_hostels, $conn_hostels);
    $query_rsEresults = sprintf("SELECT * FROM hostel_details WHERE hostel_name = %s OR institution_nearest = %s OR category = %s OR district = %s", GetSQLValueString($colname_rsEresults, "text"),GetSQLValueString($colname2_rsEresults, "text"),GetSQLValueString($colname3_rsEresults, "text"),GetSQLValueString($colname4_rsEresults, "text"));
    $rsEresults = mysql_query($query_rsEresults, $conn_hostels) or die(mysql_error());
    $row_rsEresults = mysql_fetch_assoc($rsEresults);
    $totalRows_rsEresults = mysql_num_rows($rsEresults);
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <table border="1">
      <tr>
        <td>hostel_id</td>
        <td>hostel_name</td>
        <td>institution_nearest</td>
        <td>direction_from_institution</td>
        <td>distance_from_institution</td>
        <td>category</td>
        <td>location</td>
        <td>district</td>
        <td>price_per_sem</td>
        <td>contact_person</td>
        <td>contact_numbers</td>
        <td>address</td>
        <td>remarks</td>
        <td>picture</td>
      </tr>
      <?php do { ?>
        <tr>
          <td><?php echo $row_rsEresults['hostel_id']; ?></td>
          <td><?php echo $row_rsEresults['hostel_name']; ?></td>
          <td><?php echo $row_rsEresults['institution_nearest']; ?></td>
          <td><?php echo $row_rsEresults['direction_from_institution']; ?></td>
          <td><?php echo $row_rsEresults['distance_from_institution']; ?></td>
          <td><?php echo $row_rsEresults['category']; ?></td>
          <td><?php echo $row_rsEresults['location']; ?></td>
          <td><?php echo $row_rsEresults['district']; ?></td>
          <td><?php echo $row_rsEresults['price_per_sem']; ?></td>
          <td><?php echo $row_rsEresults['contact_person']; ?></td>
          <td><?php echo $row_rsEresults['contact_numbers']; ?></td>
          <td><?php echo $row_rsEresults['address']; ?></td>
          <td><?php echo $row_rsEresults['remarks']; ?></td>
          <td><?php echo $row_rsEresults['picture']; ?></td>
        </tr>
        <?php } while ($row_rsEresults = mysql_fetch_assoc($rsEresults)); ?>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result($rsEresults);
    ?>
    Last edited by Roger; 12-28-2010 at 07:02 PM.

  8. #177
    renu is offline Newbie
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    how to display friends thumbnails as in orkut from database?
    with my database images are shown in a row and all people in database. How to select friends from database?

  9. #178
    Tech Coder is offline Newbie
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    First, THANK YOU for this code - right stuff, right time! I was able to get my database/picture display up and running in no time by following the instructions EXACTLY (those that have trouble, RTFM! - it won't work if you don't follow the instructions! Make changes after the basics work!)

    OK, on to what I trust will help several;

    STEP-BY-STEP on
    HOW TO SHOW SELECTED PICTURES IN A 4-WIDE TABLE

    After getting the basics running (showing an image), I wanted what several on this thread have asked for - A WAY TO SHOW SEVERAL IMAGES IN A TABLE. As I found no post on that, I just 'hacked' at it until it worked and I wanted to share that with you here ('cleaner' ways are welcome - I'm pretty new to coding, though get it done!).

    My goal was to make a 4-picture wide table so I could see all the pictures from my database. As we do a lot of 'online auction' stuff, mostly this is for a way to separate all the pictures into 'Item' numbers that we assign, though this should work well for those that are looking to do 'friends' or any other partial selection.

    1. Add a column to your database with the label 'Item' (or whatever works for you). I used a default of '9999999999' to make it simple to find all pictures that don't have any other 'Item' yet assigned, then as we find them and assign Item numbers, they will be grouped together under that Item number. Be sure to put your 'default' number into the 'Item' database column for ALL previously loaded pictures before trying the code!

    2. Create a .php file (I called mine 'tablepic') with EXACTLY the code below.
    Code:
     <?php 
     $con 
    mysql_connect("host","user","pass");
        if (!
    $con)
        {
        die(
    'Could not connect: ' mysql_error());
        }
        
    $db_selected mysql_select_db("db"$con);
    $item $_GET['Item'];
    echo 
    "Your selected item number is $item <br />";
    if(!isset(
    $item) || empty($item))
    {
        die(
    "Please select your item!");
    }
    else
    {
        
    $query mysql_query("SELECT * FROM db WHERE Item = '".$item."' ");
        
    ?>
        <table border="1" width = "700">
        <?php
        $i
    =0;
        echo 
    "<tr>";
        while(
    $row mysql_fetch_array($query))
        {
            
    $i++;
            
    $id $row['id'];
            echo 
    '<td><img src="seepic.php?id=' $id .'" width="194" height="165" /></td>';
            if (
    $i == ceil($i 4))
            {
                echo 
    "</tr><tr>";
            }
        }
        echo 
    $id."</tr>";
    }
    mysql_close($con);
    ?>
    3. Make sure your 'seepic.php' file looks like this (this is code taken directly from this thread and renamed)

    Code:
    <?php 
     $con 
    mysql_connect("host","user","pass");
        if (!
    $con)
        {
        die(
    'Could not connect: ' mysql_error());
        }
        
    $db_selected mysql_select_db("db"$con);
    $id $_GET['id'];
    if(!isset(
    $id) || empty($id)){
    die(
    "Please select your image!");
    }else{
    $query mysql_query("SELECT * FROM db WHERE id = '".$id."'");
    while(
    $row mysql_fetch_array($query))
    {
        
    $content $row['picture'];
        
    header('Content-type: image/jpg');
        echo 
    $content;
    }
    }
    mysql_close($con);
    ?>
    4. Be sure to change 'db', 'host', 'user' and 'pass' to your local settings!

    5. Run the 'tablepics.php' file by going to http://YOURSITE.com/tablepic.php?Item=9999999999

    You should see FOUR WIDE pictures all lined up in a nice table! ENJOY!

  10. #179
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Tech Coder, thanks for sharing your changes.

  11. #180
    batowiise is offline Newbie
    Join Date
    Jan 2011
    Posts
    17
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Thanks, this is is very simple and fine tutorial.

Closed Thread
Page 18 of 22 FirstFirst ... 81617181920 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 02-07-2011, 11:29 AM
  2. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 47
    Last Post: 01-04-2011, 08:37 PM
  3. Beginner Storing images in XML file - Part II - Displaying image
    By Jaan in forum PHP Tutorials
    Replies: 6
    Last Post: 01-04-2011, 08:35 PM
  4. display images sequentially using PHP and MySQL
    By jhanjon in forum PHP Development
    Replies: 2
    Last Post: 10-08-2009, 12:11 PM
  5. Replies: 2
    Last Post: 07-16-2009, 12:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts