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



























Recent Comments
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
How to promote my website ?
Mon, 21 Jun 2010 05:03:44 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
http://www.hanmeidayi.com/,
Sat, 19 Jun 2010 08:45:41 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
高尔夫网址大全:www.golfwebs.com.cn 高尔夫网上商城:www.yosgolf.com 高尔夫e族:www.golfhm.com 摄
Thu, 03 Jun 2010 05:05:39 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
I would like to find any site to make permalink with my site,but I can't find one site.oh my god,who can help me?my site is http://www.shuangxi-hk.com
Tue, 18 May 2010 18:25:40 +0000
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