| |
puccavn Noogle

Joined: 12 Apr 2005
1021.15 GC$
Items
|
Posted: Thu May 05, 2005 11:45 pm Post subject: 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; |
Then create new file with name: dbconn.inc, copy codes below---> save
| Code: | <?php
$link = mysql_connect ("localhost", "yourusernamehere", "yourpasshere")
or die ("Could not connect to MySQL Database");
mysql_select_db("dict", $link);
?> |
Copy codes below to a text edition
| Code: |
<?php
echo("<a href=admin.php>ACP</a><br>");
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<b>$word</b> in vietnamese is : <b>$vie</b><br>");
?>
<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);
}
?> |
save with name: index.php
Copy this code to text editor:
| Code: | <?php
echo("<a href=index.php>Home</a><br>");
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"><br>
Vietnam: <input type=text name="vie"><br>
<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);
}
?>
|
Save with name admin.php
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 )
 |
|
| Back to top |
|
|
bigmonkey Junior Googler


Joined: 21 Apr 2005
996.00 GC$
Items
|
Posted: Mon May 09, 2005 1:16 am Post subject: |
|
|
|
great job, i like your idea. I was gonna make a world dictionary for all languages I will let u know when i start that project!
Maybe u can help _________________ [Sig images removed, Please read the rules! -admin] |
|
| Back to top |
|
|
puccavn Noogle

Joined: 12 Apr 2005
1021.15 GC$
Items
|
Posted: Sat Jun 18, 2005 2:56 am Post subject: |
|
|
|
okie !!
Try the best to help you !! |
|
| Back to top |
|
|
frumau Junior Googler

Joined: 19 Jun 2005
2259.75 GC$
Items
|
Posted: Sun Jun 19, 2005 12:04 pm Post subject: |
|
|
|
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? _________________ Jasper
gateway2thailand |
|
| Back to top |
|
|
puccavn Noogle

Joined: 12 Apr 2005
1021.15 GC$
Items
|
Posted: Mon Jun 20, 2005 8:39 pm Post subject: |
|
|
|
run that query on phpmyadmin or write small PHP script to run it !!
This query will make an table in your database  |
|
| Back to top |
|
|
frumau Junior Googler

Joined: 19 Jun 2005
2259.75 GC$
Items
|
Posted: Thu Jun 23, 2005 8:13 am Post subject: 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><br>");
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"><br>
Thai: <input type=text name="th"><br>
<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><br>");
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<b>$word</b> in Thai is : <b>$vie</b><br>");
?>
<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 _________________ Jasper
gateway2thailand |
|
| Back to top |
|
|
pratik Rusty

Joined: 12 May 2005
1320.80 GC$
Items
|
Posted: Thu Jun 30, 2005 5:24 pm Post subject: |
|
|
|
| nice.. i tried it with my free hsot.. it worked then after few days later few host shut down .lol |
|
| Back to top |
|
|
frumau Junior Googler

Joined: 19 Jun 2005
2259.75 GC$
Items
|
Posted: Thu Jun 30, 2005 11:53 pm Post subject: |
|
|
|
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!! _________________ Jasper
gateway2thailand |
|
| Back to top |
|
|
gilson_rosa Noogle

Joined: 03 Oct 2005
297.10 GC$
Items
|
Posted: Mon Oct 03, 2005 5:59 pm Post subject: Chinese characters |
|
|
|
| Hy! Guys!!! I´m learning PHP and I´d like to create a Chinese-Portuguese dictionary, but how can I type Chinese characters? Portuguese has special signals and cannot be displayed properly. What should I do? |
|
| Back to top |
|
|
frumau Junior Googler

Joined: 19 Jun 2005
2259.75 GC$
Items
|
Posted: Mon Oct 03, 2005 11:12 pm Post subject: |
|
|
|
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, _________________ Jasper
gateway2thailand |
|
| Back to top |
|
|
gilson_rosa Noogle

Joined: 03 Oct 2005
297.10 GC$
Items
|
Posted: Tue Oct 04, 2005 7:03 am Post subject: DBTools Manager Professional |
|
|
|
Thanks, Frumau for your quick reply.
I´m new in the PHP thing. If you don´t mind, could you please tell me where can I set this configuration on DBTools Manager Professional?
Thanks a lot!!! |
|
| Back to top |
|
|
frumau Junior Googler

Joined: 19 Jun 2005
2259.75 GC$
Items
|
Posted: Tue Oct 04, 2005 9:25 am Post subject: |
|
|
|
Well, I use phpmyadmin. A great free of charge Mysql organizer. There I have these charset settings:
MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation: utf8_general_ci
Try to find that in your programme.
Cheers, _________________ Jasper
gateway2thailand |
|
| Back to top |
|
|
frumau Junior Googler

Joined: 19 Jun 2005
2259.75 GC$
Items
|
Posted: Tue Oct 04, 2005 9:28 am Post subject: |
|
|
|
P.S. Don't forget to make the encoding of the page which will contain de dictionary form utf-8!! With the dash(-). Otherwise people will have to change the character encoding themselves all the time to read the words.
Cheers, _________________ Jasper
gateway2thailand |
|
| Back to top |
|
|
gilson_rosa Noogle

Joined: 03 Oct 2005
297.10 GC$
Items
|
Posted: Tue Oct 04, 2005 9:45 am Post subject: |
|
|
|
| Thanks again, Frumau! I already can type in Portuguese, but I still can´t type in Chinese. I don´t know what to do. Maybe I´ll have to use some other kind of codes. |
|
| Back to top |
|
|
frumau Junior Googler

Joined: 19 Jun 2005
2259.75 GC$
Items
|
Posted: Tue Oct 04, 2005 10:01 am Post subject: |
|
|
|
Did you change the table row's collation for the chinese and portuguese char set words to utf8_unicode_ci as well?
Or try big5_chinese_ci collation for the table rows containing the chinese characters although I think utf8 should work.. And if you do try it out you should maybe change the page encoding of the page displaying the chinese words as well to big5_chinese_ci.
Cheers, _________________ Jasper
gateway2thailand |
|
| Back to top |
|
|
Sponsored Links
|
Posted: 9 Jan 2009 1:26 am Post subject: Advertisements |
|
|
|
|
|
|
| Back to top |
|
|