Home > Backend Development > PHP Tutorial > sqlite3 count query the number of rows with the same value, php code

sqlite3 count query the number of rows with the same value, php code

WBOY
Release: 2016-07-06 13:51:48
Original
1569 people have browsed it

$sql=<<SELECT COUNT(*) FROM

WHERE DATE = $date
EOF;
$ret = $db->query($ sql);
echo "count:",$ret->numColumns();

I want to use the above code to find the number of rows containing the same value in the DATE column in the table, but the result is 1 every time, and the number of rows that meet the requirements in the actual table is not 1. What is the problem? How can I modify it?

Reply content:

$sql=<<SELECT COUNT(*) FROM

WHERE DATE = $date
EOF;
$ret = $db->query($ sql);
echo "count:",$ret->numColumns();

I want to use the above code to find the number of rows containing the same value in the DATE column in the table, but the result is 1 every time, and the number of rows that meet the requirements in the actual table is not 1. What is the problem? How can I modify it?

The sqlite statement is no problem. The problem lies behind. By performing var_dump on the results obtained by executing fetchArray on $ret, we can find that
array (size=1)
'COUNT(*)' => int 1
Therefore, we can use $arr['COUNT(* )']Output the correct result

Next time try more before asking questions, my bad

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template