Posts filed under ‘php code’
javascript unescape like php function
March 29th, 2005
when you start dealing with languages (i.e. chinese) that require 8 bit encoding or more, you will learn about all the wonderful jazz of utf8, unicode, ISO etc. i was looking all over for a php function that does what javascript unescape does. normally rawurldecode would work, but…
(more…)
the mystery of querying
March 24th, 2005
if i know (or remember) more from my database class, i may have an answer for this. i was just coding my new board and was curious about which of the following query is faster:
SELECT m.regdate, m2.postnum FROM dmb_members m, dmb_members_post m2 WHERE m.uid=m2.uid AND m.uid = '".$userid."' LIMIT 1
or
SELECT m.regdate, m2.postnum FROM dmb_members m, dmb_members_post m2 WHERE m2.uid = '".$userid."' AND m.uid = '".$userid."' LIMIT 1
m.uid is a primary index while m2.uid is an index. what would be your guess?
(more…)
save arrays into database
February 28th, 2005
i’ve known this for a while but forgot to share it. there is a very easy way you can store array into database as a string. then you can grab the string from the database and convert it back into an array.
(more…)
separate template from code
February 23rd, 2005
when you do serious coding, it’s always a good idea to separate your layout design (template) from your logic code. i’m at the beginning stage rebuilding dmb. one thing i want to do very badly is to get rid of all templates in the database. every time i load a template right now it causes me a query. i want to store my templates in files because file_get_contents is less expensive than a query. and i just figured out a very easy way to do that.
store your template in a file. it can be html, text or php, whatever suits your need.
put this in your html file, name it “test.html”
this is so $test
and then use the code below:
<?php
$test = "cool";
$meep = file_get_contents("test.html");
eval("\$meep = \"$meep\";");
echo $meep;
?>
and it will print out “this is so cool” ^_^

