This is a way to simplify the SQL query function, and I hope to help you
If there is a better view, please OICQ 86804 or email:liboys@21cn.com co-study
# SQL query
# when Count=true, only the number of records is counted
function Db_query ($query, $rec = False) {
if ($rec) {
$query = Explode ("from", $query); A 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; In the future, you can call $re->xx method.
}
For example
......
# just the number of records
$query = "Select Id,name,about from table where ID > 10";
$re = Db_query ($query, true); Shape as SELECT count (*) from table where ID > 10
Print $re->reccount; Returns the number of records
#求查询结果
$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;
}
http://www.bkjia.com/PHPjc/532216.html www.bkjia.com true http://www.bkjia.com/PHPjc/532216.html techarticle This is a way to simplify the SQL query function, I hope to help you if there is a better view, please OICQ 86804 or email:liboys@21cn.com co-study # SQL query # when count=true, ...