|
||||||||||
|
|||||||
| GoogleCommunity Sponsor |
Use coupon "forum" for 50% Off! |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Noogle
![]() Join Date: Apr 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Build an online dictionary by PHP/MySQL
create a database with name: dict
and run these query Code:
CREATE TABLE `words` ( `id` tinyint(4) NOT NULL auto_increment, `eng` varchar(255) NOT NULL default '', `vie` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1; Code:
<?php
$link = mysql_connect ("localhost", "yourusernamehere", "yourpasshere")
or die ("Could not connect to MySQL Database");
mysql_select_db("dict", $link);
?>
Code:
<?php
echo("<a href=admin.php>ACP</a>
");
if(isset($_GET['act']))
{
$do=$_GET['act'];
switch($do)
{
case 'form': show_form();break;
case 'sm' : submited();break;
default : show_form; break;
}
}
else
{
show_form();
}
function show_form()
{
?>
<form name=frm method=POST action="index.php?act=sm">
Word : <input type=text name="word"> <input type=submit name="sbm" value="Submit">
</form>
<?
}
function submited()
{
require("dbconn.inc");
//if(isset($_POST['sbm']))
//{
$word=$_POST['word'];
$sql="select * from words where eng like '".$word."'";
//echo($sql);
$result=mysql_query($sql,$link);
if(@mysql_num_rows($result)!=0)
{
while($rows=mysql_fetch_array($result))
{
$vie=$rows["vie"];
}
echo("Word$word in vietnamese is : $vie
");
?>
<form name=frm method=POST action="index.php?act=sm">
Word : <input type=text name="word"> <input type="submit" name="sbm" value="Submit">
</form>
<?
}
else
echo("Don't know that word !! My database is not update!");
//}
mysql_close($link);
}
?>
Copy this code to text editor: Code:
<?php
echo("<a href=index.php>Home</a>
");
if(isset($_GET['act']))
{
$do=$_GET['act'];
switch($do)
{
case 'form': show_form(); break;
case 'sm': submited(); break;
default: show_form();
}
}
else
show_form();
function show_form()
{
?>
<form name=frm method=POST action=admin.php?act=sm>
English: <input type=text name="eng">
Vietnam: <input type=text name="vie">
<input type=submit name=sm value="Submit">
</form>
<?
}
function submited()
{
require("dbconn.inc");
if(isset($_POST['sm']))
{
$eng=$_POST['eng'];
$vie=$_POST['vie'];
$sql="Insert into words(eng, vie) values('".$eng."','".$vie."')";
$res=mysql_query($sql,$link);
//header("Location: admin.php");
?>
<script language=Javascript>window.location="admin.php";</script>
<?
}
else
echo("Insert data !!");
mysql_close($link);
}
?>
upload these three files to your host admin.php to insert more words into your db base on these code you can make more dict, exp: fr-vie comp... and create more field forexp: adjective, noun, verb... sorry for my bad english ( i'm from Vietnam ) |
|
|
|
|
Sponsored Links
|
|
|
|
#4 (permalink) |
|
Junior Googler
![]() Join Date: Jun 2005
Posts: 45
Thanks: 0
Thanked 1 Time in 1 Post
![]() |
I am new to php and have a question. I would like to make a dictionary the way you told but when you mention: "create a database with name: dict
and run these query".", do you mean that I should put that query file in the database file of my root directory? |
|
|
|
|
|
#6 (permalink) |
|
Junior Googler
![]() Join Date: Jun 2005
Posts: 45
Thanks: 0
Thanked 1 Time in 1 Post
![]() |
dictionary
Well I got phpmyadmin working and I entered your info. I adapted it cause I want a Dutch Thai Dictionary. But somehow the data I enter doesn't reach my table in the database. Here's your slightly altered script:
Admin.php: <?php echo("<a href=index.php>Home</a> "); if(isset($_GET['act'])) { $do=$_GET['act']; switch($do) { case 'form': show_form(); break; case 'sm': submited(); break; default: show_form(); } } else show_form(); function show_form() { ?> <form name=frm method=POST action=admin.php?act=sm> Nederlands: <input type=text name="nl"> Thai: <input type=text name="th"> <input type=submit name=sm value="Submit"> </form> <? } function submited() { require("dbconn.inc"); if(isset($_POST['sm'])) { $nl=$_POST['nl']; $th=$_POST['th']; $sql="Insert into words(nl, th) values('".$nl."','".$th."')"; $res=mysql_query($sql,$link); //header("Location: admin.php"); ?> <script language=Javascript>window.location="admin.php";</script> <? } else echo("Insert data !!"); mysql_close($link); } ?> And index.php: <?php echo("<a href=admin.php>ACP</a> "); if(isset($_GET['act'])) { $do=$_GET['act']; switch($do) { case 'form': show_form();break; case 'sm' : submited();break; default : show_form; break; } } else { show_form(); } function show_form() { ?><title>Woordenboek</title> <form name=frm method=POST action="index.php?act=sm"> Word : <input type=text name="word"> <input type=submit name="sbm" value="Submit"> </form> <? } function submited() { require("dbconn.inc"); //if(isset($_POST['sbm'])) //{ $word=$_POST['word']; $sql="select * from words where eng like '".$word."'"; //echo($sql); $result=mysql_query($sql,$link); if(@mysql_num_rows($result)!=0) { while($rows=mysql_fetch_array($result)) { $vie=$rows["vie"]; } echo("Word$word in Thai is : $vie "); ?> <form name=frm method=POST action="index.php?act=sm"> Word : <input type=text name="word"> <input type="submit" name="sbm" value="Submit"> </form> <? } else echo("Don't know that word !! My database is not update!"); //} mysql_close($link); } ?> Do you see any errors? Thanx, Jasper |
|
|
|
|
|
#8 (permalink) |
|
Junior Googler
![]() Join Date: Jun 2005
Posts: 45
Thanks: 0
Thanked 1 Time in 1 Post
![]() |
I fixed the problem. Had to change the char-set code for the connection to the Mysql server, for the index page and for the Mysql database and table to UTF-8 and now everything is working out very nicely. Thanks for the code!!
|
|
|
|
|
|
#10 (permalink) |
|
Junior Googler
![]() Join Date: Jun 2005
Posts: 45
Thanks: 0
Thanked 1 Time in 1 Post
![]() |
Use Unicode as char set for the transfer of the code, the database and the page you will have your dictionary on (encoding="utf-8" see Gateway2Thailand Dictionary ). I think unicode covers chinese characters as well. Portuguese for sure.
Cheers, |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is the longest word in the dictionary? | kcmandava | Chit Chat | 18 | 12-02-2008 07:19 PM |
| Chav makes the dictionary | dude66 | Chit Chat | 6 | 06-16-2005 09:22 AM |
| Google no longer using dictionary.com; now answers.com | intelliot | All About Google | 11 | 01-30-2005 11:47 AM |
| Googler in dictionary | malapati | All About Google | 5 | 11-07-2004 07:51 PM |
| What is the longest word in the dictionary? | kcmandava | Chit Chat | 17 | 01-01-1970 07:00 PM |