new PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ada
Forum Newbie
Posts: 1
Joined: Mon Dec 09, 2013 3:48 am

new PHP

Post by ada »

Hi Everyone....

I am first in php... I come across with problem... I have install XAMPP and work with php.. I have table 1 in database prim

My table 1 have 3 field Ad (type varchar) daimi (type int) ish (type int)

the connection with table I already make so that I take the anwer to the following ...
$count = mysql_numrows(mysql_query("select * from `table 1` "));
PRINT "<CENTER>chislo zapisey $count <BR><BR>";

but when I add where to this string it make problems
$count = mysql_numrows(mysql_query("select * from `table 1` where `Ad`=`Qazax rayonu`"));
PRINT "<CENTER>chislo zapisey $count <BR><BR>";


in the screen it gives the following explanation....
Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\rrson.php on line 40
chislo zapisey

Pls. help me what I have to do where is my mistakes????
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: new PHP

Post by requinix »

That error message means there was a problem with the query and it could not be executed. Specifically, you used the wrong quotes for the "Qazax rayonu": backticks `s are only for names in the database so you need to use single quotes 's or double quotes "s.
Also, your method of getting the row count is very inefficient. You can use MySQL's COUNT() function to tell you how many rows come back from a query and without having to actually get all the rows (rows that you don't need to read through).

Use

Code: Select all

$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `table 1` WHERE `Ad` = 'Qazax rayonu'"), 0, 0);
Post Reply