Chinese Idiom Database Updates
I hit a brick wall with my plugin development, so I spent some time updating the Chinese Idiom Database.
A long time ago a kind person emailed me with some suggestions for the database. I thought all of his ideas were wonderful, and have just finished implementing them all, plus some minor improvements to the code, which will make further updates less painful. As this database was my first attempt at PHP programming, the code was … messy.
I also implemented a few things I wanted to do a long time ago, but couldn’t because of the state the code was in.
These are the changes:
There is now an “All Idioms” page that displays all the idioms’ English meaning, which will make it possible for people just starting to learn Chinese to browse idioms.
Both the English and the Chinese “All Idioms” pages’ links open in a Greybox above the page, which avoids a full page load.
One may move forward or backwards through the idioms within the Greybox, using the “Previous, Next” links.
Idioms may be given thumbs-up/down ratings.
Each time an idiom is returned as a search result or viewed by following a link from one of the “All Idioms” pages, a count is incremented. This will allow us to see which idioms have been viewed the most, which will give me some idea of how many people actually use the database (if any at all).
The hardest part was making the Greybox pages show the “Next/Previous” links, but that was only hard because I am a still pretty new to MySQL. During the page generation, I needed to be able to pull the idiom/English translation from the next and previous entries in the list of all idioms. After much irritation, I managed to do it like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | $result = mysql_query("SELECT * FROM idioms WHERE zh_idiom!=''") or die(mysql_error());
$result_copy = mysql_query("SELECT * FROM idioms WHERE zh_idiom!=''") or die(mysql_error());
$prev = mysql_result($result_copy, mysql_num_rows($result_copy)-1 ,'zh_idiom' );
$next = mysql_result($result_copy, 1 ,'zh_idiom');
$count = 0;
while($row = mysql_fetch_array($result)) { //make one page for each idiom
$file_name = $row['zh_idiom'] . ".php";
$file = fopen($file_name,"w");
$update_count = "<?php ".'$'."dbhost = 'localhost';
".'$'."dbuser = 'pagesofi_student';
".'$'."dbpass = '".'$'."a|Qt;jXg+Nf';
".'$'."dbname = 'pagesofi_idioms';
".'$'."conn = mysql_connect(".'$'."dbhost, ".'$'."dbuser, ".'$'."dbpass) or die('Error connecting to mysql');
mysql_select_db('pagesofi_idioms');
mysql_query(\"UPDATE idioms SET times_accessed=times_accessed+1 WHERE zh_idiom='".$row['zh_idiom']."'\") or die(mysql_error());
".'$'."result = mysql_query(\"SELECT * FROM idioms WHERE zh_idiom='".$row['zh_idiom']."'\");
".'$'."count = mysql_fetch_array(".'$'."result);
?>";
$top = "<META http-equiv=Content-Type content='text/html; charset=UTF-8'><head><link rel='stylesheet' type='text/css' media='screen' href='idioms_individual.css' /></head>
".$update_count ."
<title>".$row['zh_idiom']."</title>
<html><body><p></p>
<p>".$row['zh_idiom']."</p><br>".$row['pinyin']."<br><br>". "<p1>".stripslashes($row['en_translation'])."</p1><br><br><p5>" . $row['example'] . "</p5><br/><br/><p2>Keywords: " .$row['key_word']."<br/>Viewed <?php echo " .'$'. "count['times_accessed'] ?> times. <br/>Entered by ".$row['creator']." on ".$row['date_created']."</p2><br/><div class='js-kit-rating' view='score' title='".$row['zh_idiom']."' path='".$row['zh_idiom']."' permalink='http://pagesofinterest.net/idiom/search_results.php?zhongwen=".$row['zh_idiom']."'></div>
<div id='nextPrev'><a id='prev' href='".$prev.".php'>Previous</a><a id='next' href='".$next.".php'>Next</a></div>
<script src='http://js-kit.com/ratings.js'></script>
</body>
</html>";
fwrite($file, $top); |
I’m sure that my way is not the best way, but it works. If the database ever becomes massive, or I can’t find anything better to do, I’ll look at changing it.
As this script is only run when an idiom is added, so a little inefficiency is OK, right?
Shhh… I’ll make it better later, promise!
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title
Been a Long Time…
It sure has been a long time since I posted here.
I’ve been busy… Though I can’t say this semester has been horrible, I can’t say it has been very enjoyable, either. Being reminded that I had a COMP paper remaining, after coming back from our wonderful trip to China was not fun. That paper is very very hard, and makes me stressed. Even after completing an assignment, I am not sure what we were meant to do. My assignments tend to pass the required tests, however, regardless of their creators lack of understanding. I have one more assignment left for this paper, and I hear from the lecturer that it is “not going to be easyâ€. I think he was implying that the previous 5 assignments have been easy. I assure you, they were not. I shudder to think what hideous task he has waiting for us. He really makes work for himself, when he gives me such difficult work. He must know that I will be emailing him every half hour with (what would be to him, I guess) inane and obvious questions. Questions like:
So the binary “whatchamacallits” for each index could be:
000
010
100
110
001
011
101
111
Right?
This would let “us” know which of the variables were true for each index, and allow “us” to do our thing?
Is this at all correct?
Am I getting closer?
Mike
Actually, that is less desperate than normal. He answers them promptly, and I usually find the comments helpful.
Though I don’t like the paper, I don’t mind being forced to complete it (it is a compulsory for my major), as it makes other, non AI related programming seem like actual fun. For example, this weekend I created The Chinese Idiom Database, partly because I wanted to learn how to use MySQL & PHP, and partly because the other idiom databases I could find were … somewhat lacking. One of them appeared initially promising, returning a good number of idioms for my search “orangeâ€, but it fell over when I selected an idiom to view. The idiom’s information was presented in some encoding that my browser doesn’t understand:

Stupid Big5
This may, or may not be their fault. Whatever, I can’t use their database. There were one or two others, but either the layout or the search method were seriously flawed.
Mainly I wanted to make my own.
You can find it by clicking on the “Idiom DB / æˆè¯èµ„料库†link in the sidebar.
I’d say I enjoyed about 15% of the creation process. The rest was extremely frustrating. Prior to creating the database and associated pages, I knew NOTHING about MySQL or PHP. This meant that any error I got didn’t make sense to me, and help (in the form of Google) would more often than not confuse the crap out of me. I found two great tutorials, and combined with the excellent W3Schools site, I managed to throw together what you’ll see, if you’d only CHECK IT OUT!
The tutorials are: a MySQL tutoral, a short tutorial on how to create a login/registration area, and W3Schools.
The thing that I like the most about The Idiom Database is that you can create an account and add idioms yourself! I hope that people do, as I know there are a lot of Chinese Idioms out there, and I know I can’t add them all myself. Users can also edit idioms they have entered, or if they have special permissions, can edit any entry. If you think you deserve special permissions, please send me an email! The reason I had to make it so people can only edit their own entries is because I don’t want one bastard to come along and screw it all up by changing all the entries to something rude or nonsensical. If people start entering stupid things, Ill change their account permissions so that any idiom entered by them goes into a moderation queue, waiting for me to OK the entry before it gets displayed with other idioms in search results.
Well, that is all for now, I have to go out. When I get back I’ll let you know about other things that have been going on!
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title



























Recent Comments
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
http://store.taobao.com/shop/view_shop.htm?asker=wangwang&shop_nick=a333b444
http://item.taobao.com/auction/item_detail-0db2-40a79e949a57400b6b96edd149670677.htm
http://item.taobao.com/auction/item_detail-0db2-1d66cafb681edb96c634b894d2b1df3f.htm
http://item.taobao.com/auction/item_detail-0db2-a37ac99a003784d0c9b38150416d4c58.htm
http://item.taobao.com/auction/item_detail-0db2-f84bf08e8c573335b7d7ffe73a9d611b.htm
http://item.taobao.com/auction/item_detail-0db2-61c03a65b354488484ea0ec3076785b2.htm
http://item.taobao.com/auction/item_detail-0db2-e61b6c352c15689ee7eeca843f5345da.htm
http://item.taobao.com/auction/item_detail-0db2-958a432e957ab5c9e9b4fd6326a6ff55.htm
http://item.taobao.com/auction/item_detail-0db2-1d66cafb681edb96c634b894d2b1df3f.htm
http://item.taobao.com/auction/item_detail-0db2-484419d0d030152d16dd9dd2039c94c2.htm
http://item.taobao.com/auction/item_detail-0db2-43831f4a2dc611bccd1024ca3cf2b5f9.htm
http://item.taobao.com/auction/item_detail.htm?item_num_id=4955248190
http://item.taobao.com/auction/item_detail.htm?item_num_id=4957300818
http://item.taobao.com/auction/item_detail.htm?item_num_id=4957109628
Tue, 11 May 2010 15:02:41 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
http://a333b444.taobao.com
Tue, 11 May 2010 14:55:51 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
GOOD
Tue, 11 May 2010 14:46:49 +0000
Installing Jdownloader In Ubuntu
Very nice tutorial, works like charm, ty very much
cheers!
Fri, 02 Apr 2010 10:58:11 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
http:www.qq8080.com.cn
Fri, 02 Apr 2010 06:49:22 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
http://www.ioiojewelry.com
Mon, 29 Mar 2010 04:02:13 +0000