
正文
php数据库表输出到网页 php从数据库取数据输出
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php查询数据库并在网页上输出结果
$sql = 'SELECT COUNT( * ) FROM DAY WHERE id_u =1' ;
$resault = $db-getAll($sql);
//
function getAll($sql)
{
$res = $this-query($sql);
if ($res !== false)
{
$arr = array();
while ($row = mysql_fetch_assoc($res))
{
$arr[] = $row;
}
return $arr;
}
else
{
return false;
}
}
//
function query($sql, $type = '')
{
if ($this-link_id === NULL)
{
$this-connect($this-settings['dbhost'], $this-settings['dbuser'], $this-settings['dbpw'], $this-settings['dbname'], $this-settings['charset'], $this-settings['pconnect']);
$this-settings = array();
}
if ($this-queryCount++ = 99)
{
$this-queryLog[] = $sql;
}
if ($this-queryTime == '')
{
if (PHP_VERSION = '5.0.0')
{
$this-queryTime = microtime(true);
}
else
{
$this-queryTime = microtime();
}
}
/* 当当前的时间大于类初始化时间的时候,自动执行 ping 这个自动重新连接操作 */
if (PHP_VERSION = '4.3' time() $this-starttime + 1)
{
mysql_ping($this-link_id);
}
if (!($query = mysql_query($sql, $this-link_id)) $type != 'SILENT')
{
$this-error_message[]['message'] = 'MySQL Query Error';
$this-error_message[]['sql'] = $sql;
$this-error_message[]['error'] = mysql_error($this-link_id);
$this-error_message[]['errno'] = mysql_errno($this-link_id);
$this-ErrorMsg();
return false;
}
if (defined('DEBUG_MODE') (DEBUG_MODE 8) == 8)
{
$logfilename = $this-root_path . DATA_DIR . '/mysql_query_' . $this-dbhash . '_' . date('Y_m_d') . '.log';
$str = $sql . "\n\n";
if (PHP_VERSION = '5.0')
{
file_put_contents($logfilename, $str, FILE_APPEND);
}
else
{
$fp = @fopen($logfilename, 'ab+');
if ($fp)
{
fwrite($fp, $str);
fclose($fp);
}
}
}
return $query;
}
相关问答
Q1: php怎么能把数据库里的数据自动调用到网页上显示出来
mysql_select_db($database);
要是
?php
$con = mysql_connect("localhost","root","");mysql_select_db($sql);
$result=mysql_query('select name from tag_cate where id=3');mysql_close($con);
?
还是无内容显示咋办php数据库表输出到网页?sql是数据库名。
则
?php
$con = mysql_connect("localhost","root","");mysql_select_db($sql);
//$result是记过集好不好php数据库表输出到网页,还有php数据库表输出到网页你的输出呢?echo?
$result=mysql_query('select name from tag_cate where id=3') or die('ERROR : '.mysql_error());if($result){
if (mysql_num_rows($result) == 0) {
while($row = mysql_fetch_assoc($result)){echo $row['name'].'';
}
}
mysql_free_result($result);
}
mysql_close($con);
Q2: php网页中调用php脚本查询数据库结果输出到当前页面
php数据库表输出到网页你要输出什么php数据库表输出到网页?php数据库表输出到网页我就假设两个条件是数字php数据库表输出到网页,选好条件提交后php数据库表输出到网页,显示条件1还是条件2吧。
form action="" method="post"
label条件1:
select name="select1"
option value="0" selected="selected"选项1/option
option value="1"选项2/option
/select
/label
label 条件2:
select name="select2"
option value="0" selected="selected"选项1/option
option value="1"选项2option
option value="2"选项3/option
/select
/label
input name="b1" type="submit" value="查询" /
?php
if($_POST['select1']$_POST['select2']){
echo $_POST['select1']."".$_POST['select2'];
}else if($_POST['select1']$_POST['select2']){
echo $_POST['select1']."".$_POST['select2'];
}
else if($_POST['select1']=$_POST['select2']){
echo $_POST['select1']."=".$_POST['select2'];
}
?
Q3: PHP 如何将数据库中的数据输出到HTML的表格中
?php
$sql=mysql_query("select * from news");
while($row=mysql_fetch_assoc($sql)){
?
tr
td?php echo $row['title'];?/td
/tr
?php
}
?
输出到TD里面就行了
关于php数据库表输出到网页和php从数据库取数据输出的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







