F
F
fug353812016-02-19 00:30:17
PHP
fug35381, 2016-02-19 00:30:17

Why is it impossible to determine the number of results in a query to mysql in php?

Why is it impossible to determine the number of results in a query to mysql in php?

$db = mysql_connect($host,$user,$password);
mysql_select_db($basename, $db);
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

$result = mysql_query("SELECT * FROM keywords WHERE keyword = 'photo онлайн'");
$total = mysql_num_rows($result);
echo $total;

$result = mysql_query("SELECT * FROM keywords WHERE keyword = 'modeling websites'");
$total = mysql_num_rows($result);
echo $total;

result: 01
tried to execute the request manually and everything is fine, but does not want to use the script

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kostya00723, 2016-02-19
@fug35381

"SELECT COUNT(*) FROM keywords WHERE keyword = 'modeling websites'"
Try this query, then you won't need num rows at all.
The database will return the number of records itself

I
Igor Voronov, 2016-02-19
@ivoronov

To be honest, I'm not really eager to check your code, so I'll add: Have you tried SQL_CALC_FOUND_ROWS + FOUND_ROWS()?
And you don't need any SELECT counts. For this, just, there is FOUND_ROWS. Check out the documentation. Everything is simple.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question