How do i display images from my database?

Discussion in 'PHP' started by joejokjas, May 14, 2011.

  1. #1
    Hello peeps.
    I have setup an image table in my database to store my images as bloob type. My problem is that i do not know how to display the images in the db from my web search page. Anytime i enter a searh query, it will display the keyword & the image name but it will not display the image itself. rather it displays long sql codes.

    Here are my php codes;

    Imageindex.php

    <html>
    <style type="text/css">
    body {
            background-color: #FFF;
    }
    body,td,th {
            color: #000;
    }
    </style>
    
     <form action = 'imagesearch.php' method = 'GET''>
    
             <center>
    
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p><font size="5">IMAGE DICTIONARY</font><font size="5" face="sans serif"><br>
                
                <input type = 'text' size = '50' name = 'search'> <input type = 'submit' name= 'submit' value = 'search'>
          </font></p>
    </center>
            
     </form>
    </html>
    PHP:

    imagesearch.php

    <style type="text/css">
    body {
            background-color: #FFF;
    }
    </style>
    <?php
    
    //get data
    $button = $_GET['submit'];
    $search = $_GET['search'];
    $x = "";
    $construct = "";
    if (!$button){
            echo "You didint submit a keyword.";
    }
    else{
            if (strlen($search)<=2) {
                    echo "Search term too short.";
            }
            else {
                    echo "You searched for <b>$search</b><hr size='1'>";
                    
                    //connect to database
                    mysql_connect("localhost","root","");
                    mysql_select_db("searchengine");
                    
                    
                            
                            //explode our search term
                            $search_exploded = explode(" ",$search);
                            
                            foreach($search_exploded as $search_each) {
                                    
                                    //constuct query
                                    $x++; 
                                    if ($x==1) {
                                            $construct .= "keywords LIKE '%$search_each%'";
                                    }
                                    else {
                                            $construct .= " OR keywords LIKE '%$search_each%'";
                                    }
                            }
                            
                            //echo out construct
                            
                            $construct = "SELECT * FROM images WHERE $construct";
                            $run = mysql_query($construct) or die(mysql_error());
                            
                            $foundnum = mysql_num_rows($run);
                            
                            if ($foundnum==0) {
                                    echo "No results found."; 
                            }
                            else {
                                    echo "$foundnum results found!<p>";
                                    while ($runrows = mysql_fetch_assoc($run)) {
                                            //get data
                                            $name = $runrows['name'];
                                            $image = $runrows['image'];
                                          
                                            
                                            echo "
                                            <b>$name</b><br>
                                            $image<br>
                                           
                                            ";
                                    }
                            }
            }
    }
    PHP:
     
    joejokjas, May 14, 2011 IP
  2. medzmay

    medzmay Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this. i never use bloob type :(

     
    medzmay, May 15, 2011 IP