Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    php search result for a dictionary

    Hi All,
    I have been in design world more than 5 years but I'm newbee in coding. And This time I want to prepare a dictionary for Italian - Turkish and Turkish - Italian. I prepared a simple database in phpmyadmin as an example to see the result (it has almost 10 words) and found some php codes to get the informations from the database.

    This is the code for tha page I do my searching is: search.htm

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form method="post" action="search_result.php">
    <input type="text" name="search" size=25 maxlength=25>
    <input type="Submit" name="Submit" value="Submit">
    </form>
    
    </body>
    </html>
    and this is my search result page:

    Code:
    <html>
    <body>
    
    <table width="100%" border="1" cellspacing="0" cellpadding="2">
    <tr>
    <th bgcolor="#CCCCCC" width=5%>
    
    
    <?
    //MySQL Connect.
    mysql_connect("localhost","username","password"); 
    //Database name.
    mysql_select_db("db_name"); 
    
    $search=$_POST["search"];
    
    
    //The names of the db that I made ready
    $result = $result = mysql_query("SELECT * FROM dictionary WHERE tr LIKE '%$search%' OR it LIKE '%$search%'");
    while($r=mysql_fetch_array($result))
    {     
       $tr=$r["tr"];
       $it=$r["it"];
       $id=$r["id"];
    
       //I see the result here.
       echo "$tr -> $it      ";
       echo "$it -> $tr      ";
              echo "<a href=".$url.">".$url."</a> <br>";
    }
    
    
    
    ?>
    </th>
    
    </tr>
    </table>
    </body>
    </html>
    And now here my questions:

    * How can I do this search on one page and keeping the search box still exist for another search. (I mean after I make a search I want to see the results under the search box)

    AND

    * How can I make a design for that page? Now I created an area (you can see the html codes above) in which I can see the results but the results always seem like this "Turkish word -> Italian corresponding , Italian word -> Turkish corresponding.

    How can I solve this problem.

    Thanks a lot
    bailey

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You could just post the form to the same search page that creates the form, that way the HTML for the form is always there. Put a block of PHP below the search form that checks to see if the form has been submitted and if it has, produce search results.

    Since you're using MySQL you may want to consider using a full text index rather than the "like '%'" method-- much faster and more robust.

    http://dev.mysql.com/doc/refman/5.0/...xt-search.html

  • #3
    New Coder
    Join Date
    Aug 2009
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi Fumigator. I worked on it by myself and did the thing you said before you wrote here. Happy for myself.

    Now I have a code which you can see below and my problem is that when I open the page it shows every entry of database. Every words. And also when I do a blank search, it shows up eveything. How can I solve that?

    my second quest.

    guess that I am looking for the word = "house" but it shows the word "housewife" before "house". How can I solve that?

    and my third question: how can I add "did you mean that" option when a user writes the word wrong??


    By the way I am using phpmyadmin and couldnt get how to use the useful things you gave me the link of

    regards

    my new codes

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9">
    <title>Untitled Document</title>
    </head>
    
    <BODY 
        BGCOLOR="#2a2a2a"
        TEXT="#000000"
        LINK="#0000FF"
        VLINK="#FF66FF"
        ALINK="#FF0000"
        >
    <br><br><br><br>
    <center>
    <p><font face="verdana" size="2" color="#ffffff"> <b>Turkish - Italiano // Italiano --> Turkish </b> </p>
    <form method="post" action="search_result.php">
    <input type="text" name="search" size=45 maxlength=45>
    <input type="Submit" name="Ara" value="Search">
    </form>
    
    
    <br><br><br><br>
    <table width="800px" border="1" cellspacing="0" cellpadding="2">
    <tr>
    <th bgcolor="#2a2a2a" width=5%>
    <font face="verdana" size="2" color="#ffffff">
    
    <center>
    
    <?
    //MySQL connection.
    mysql_connect("localhost","my_username","password"); 
    //Database name.
    mysql_select_db("my_dbname"); 
    
    $search=$_POST["search"];
    
    
    //the informations that I had prepared.
    $result = $result = mysql_query("SELECT * FROM dictionary WHERE tr LIKE '%$search%' OR it LIKE '%$search%'");
    while($r=mysql_fetch_array($result))
    {     
       $tr=$r["tr"];
       $it=$r["it"];
       $id=$r["id"];
    
       //and here the result.
       echo "$tr = $it      "; 
    
    
              echo "<a href=".$url.">".$url."</a> <br>";
    }
    
    if ($id==0){
    echo "No search result.";
    }
    
    
    ?>
    
    
    
    
    </center>
    </font>
    </th>
    </tr>
    </table>
    
    </body>
    </html>


  •  

    Posting Permissions

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