Image search program

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

  1. #1
    Please how can i further make the code below to search for images. The program can currently search for titles, descriptions and their urls but i need to also include an image search capability to it. I need some help please.......

    index.php
    <form action = 'search.php method = 'GET''>
    
            <font face = 'sans serif' size = '5'> <center>
    
            My Search Engine<br>
    
            <input type = 'text' size = '50' name = 'search'> <input type = 'submit' name= 'submit' value = 'search'> 
            
    
            </center>
            </font>
       </form>
      </html>
    
    PHP:

    search.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 searchengine 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
                                            $title = $runrows['title'];
                                            $desc = $runrows['description'];
                                            $url = $runrows['url'];
                                            
                                            echo "
                                            <b>$title</b><br>
                                            $desc<br>
                                            <a href='$url'>$url</a><p>
                                            ";
                                    }
                            }
            }
    }
    PHP:
     
    joejokjas, May 10, 2011 IP
  2. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Your database should have urls as well...
     
    ker, May 10, 2011 IP