...

View Full Version : php search result for a dictionary



may_bailey
08-24-2009, 12:47 PM
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


<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:



<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

Fumigator
08-24-2009, 05:02 PM
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/en/fulltext-search.html

may_bailey
08-24-2009, 06:04 PM
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


<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum