This is a method to simplify SQL query functions.
If you have a better view, Please study together with OICQ 86804 or EMAIL: liboys@21cn.com
# SQL query
# When count = true, only the number of records is calculated.
Function db_query ($ query, $ rec = false ){
If ($ rec ){
$ Query = explode ("from", $ query); // simple Truncation
$ Query = "select count (*) from". $ query [1];
}
$ Result = mysql_query ($ query) or die (mysql_error ());
If ($ rec ){
$ Rows = mysql_fetch_row ($ result );
$ Reccount = $ rows [0];
}
Else {
$ Reccount = mysql_num_rows ($ result );
}
If ($ reccount ){
$ Re-> result = $ result;
$ Re-> reccount = $ reccount;
}
Else {
$ Re = false;
}
Return $ re; // you can call the $ re-> xx method later.
}
For example
......
# Count only records
$ Query = "select id, name, about from table where id> 10 ";
$ Re = db_query ($ query, true); // select count (*) from table where id> 10
Print $ re-> reccount; // number of returned records
# Query results
$ Query = "select id, name, about from table where id> 10 ";
$ Re = db_query ($ query );
For ($ I = 0; $ I <$ re-> reccount; $ I ++ ){
$ Rows = mysql_fetch_object ($ re-> result );
Print $ rows-> id;
}