php用 if語句 如何輸出數據庫內容
先定義頭部信息,表示輸出一個excel。
然后再以table的形式把數據庫的信息循環的echo出來。
header("Content-type:application/*-excel");
header("Content-Disposition:filename=xls_*");
$cfg_dbhost = 'localhost';
$cfg_dbname = 'testdb';
$cfg_dbuser = 'root';
$cfg_dbpwd = 'root';
$cfg_db_language = 'utf8';
// END 配置
//鏈接數據庫
$link = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
mysql_select_db($cfg_dbname);
//選擇編碼 *
mysql_query("set names ".$cfg_db_language);
//users表
$sql = "desc users";
$res = mysql_query($sql);
echo "";
//導出表頭(也就是表中擁有的字段)
while($row = mysql_fetch_array($res)){
$t_field[] = $row['Field']; //Field中的F要大寫,否則沒有結果
echo "".$row['Field']."";
}
echo "";
//導出100條數據
$sql = "select * from users limit 100";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)){
echo "";
foreach($t_field as $f_key){
echo "".$row[$f_key]."";
}
echo "";
}
echo "";
?>
請教一個php+mysql多條件查詢的語句
一般方法是這樣的:
$cond="where addtime between '$starttime' and '$endtime'";
if ($work!='') $cond.=" and work='$work'";
if ($user!='') $cond.=" and user='$user'";
if ($text!='') $cond.=" and text like '%$text%'";
$sql="select addtime from table $cond";
。
mysql_query($sql)
。。..
能夠明白我的思路吧?不明白請說明。
補充:
調試語句應該這樣:
if (!$result)
echo "SQL=$sql, ERROR=".mysql_error();
轉載請注明出處華閱文章網 » phpmysqlif語句