views:

31

answers:

2

I have a mysql database which allocate:

iid, name, description, url, namecategory, idcategory, nametopic, idtopic

How can i know the number of entries that has categoryid=1 and topicid=1?

I've tried

$result = mysql_query("SELECT COUNT(id) 
                         FROM videos 
                        WHERE idcategory = 1 
                          AND idtopic = 1")

...but it hasn't worked!

A: 

you have stated that column names are idcategory and idtopic, and in the query you use categoryid and topicid.

Make those match and then try it out.

Axarydax
not work. In my file I write the names ok, but when i write on this computer i change the name....
skiria
A: 

Run this code and paste the result:

$result = mysql_query("SELECT COUNT(id) AS cnt FROM videos WHERE idcategory=1 AND idtopic=1");
$row = mysql_fetch_assoc ($result);
var_dump ($row);
Piotr Pankowski
Where does i get the result? I run my code from a webbrowser.
skiria
On screen. You should see something like:array ('cnt' => X) Where X is number of records found
Piotr Pankowski
bool(false) 15 times
skiria
Add error_reporting(E_ALL); ini_set("display_errors", 1); at begging of your code. Btw are you connected to mysql?
Piotr Pankowski
warning: mysql_fetch_asoc(): supplied argument is not a valid MySQL result resource in /../name.php on line ..
skiria
try: print mysql_error(); after mysql_query
Piotr Pankowski
FUNCTION archivos.COUNT does not exist
skiria
I have a database called archivos that has Category Topic and videos. On videos database I have the items that I write on my question.
skiria
I guess that you have a space between COUNT and (id).
Piotr Pankowski
ok. now I get the array(1) cnt=1...
skiria
Great :) This what you should get
Piotr Pankowski
but now how can I get the number of rows? count the number of entries with idcat and idtop..??
skiria
You just did. Number of rows is available via $row['cnt'] in PHP.
Piotr Pankowski
ahm... ok, it works!! Thanks for the patience... I just start to use mysql databases...
skiria
Glad to help. btw you should accept helpful answers to your questions.
Piotr Pankowski