php查询数据库并在网页上输出结果

$aa=SELECTCOUNT(*)FROMDAYWHEREid_u=1;echo$aa;我想查出最后id_u=1一共有多少条数据,并把最后的值输出出来,该怎么做?... $aa = SELECT COUNT( * ) FROM DAY WHERE id_u =1;
echo $aa;

我想查出最后id_u=1一共有多少条数据,并把最后的值输出出来,该怎么做?
展开
 我来答
匿名用户
2015-12-11
展开全部
$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;
}
追问
谢谢
不过我只想要如何得到查询SQL后的结果...
追答
$count = $db->getOne($sql);
function getOne($sql, $limited = false)
{
if ($limited == true)
{
$sql = trim($sql . ' LIMIT 1');
}

$res = $this->query($sql);
if ($res !== false)
{
$row = mysql_fetch_row($res);

if ($row !== false)
{
return $row[0];
}
else
{
return '';
}
}
else
{
return false;
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式