This is a way to simplify the SQL query function. I hope it will be helpful to you
If you have a better opinion, please OICQ 86804 or EMAIL: liboys@21cn.com to study together
# SQL query
# When When count=true, only count the number of records
function db_query($query, $rec = false) {
if($rec) {
$query = explode("from", $query ); // Simple interception
$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 use the $re->xx method to call in the future
}
For example
...
# Just ask for the number of records
$query = "select id,name,about from table where id > 10";
$re = db_query($query,true); //Form like select count(*) from table where id > 10
print $re->reccount; //Return the number of records
#Request Query results
$query = "select id,name,about from table where id > 10";