Hey guys, Can any one help me with this error : Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in z:\home\localhost\www\test\my-site\top.php on line 70 ---------- in top.php : $get_language=mysql_query("select * from tbl_language where is_active='t'"); if (mysql_num_rows($get_language)>1) { Why do i get the error on my machine ? it works fine on online , server .. Thank you all
you're passing a result set to mysql_num_rows, not a link identifier. if you only have one connection to the db, just use mysql_num_rows() if ( mysql_num_rows() > 1 ) { ... } PHP:
Try this query directly on phpMyadmin or on the MySQL console of your machine select * from tbl_language where is_active='t';
Yes , it works fine on phpMyadmin . I got 3 rows from there . I tryed as you but i got the same error. I tyred this too : $get_language=mysql_query("select * from tbl_language where is_active='t'"); $count2=mysql_num_rows(); or like this : $get_language=mysql_query("select * from tbl_language where is_active='t'"); $count2=mysql_num_rows($get_language); But no luck.. is it becouse of settings , or problem with connecting to database with top.php ?
Have you tried displaying the rows returned by the query ? That may help to reveal where the problem is. Brew
Are you sure? I decided to verify and yes, if you are going to supply an argument, it is supposed to be a result set, not a link identifier, see php.net docs: mysql_num_rows() PHP: ziya, get into a habit of catching errors. A simple thing to do in this case is to use this at the end of each query: mysql_query('SELECT * FROM table...') or die(mysql_error()); PHP:
-------- ziya, get into a habit of catching errors. A simple thing to do in this case is to use this at the end of each query: mysql_query('SELECT * FROM table...') or die(mysql_error()); PHP: [/QUOTE] ----------- Thanks for tellig the tip.. I did as u told And i got error "No database selected " error.. How can i check this ? Thank you all
thanks all for your help.. I fixed that error.. I had there : db.php in wich there were writen config.php in require. And i got lost in that include and reuqire files.. i have deleted config.php. i copied and pasted all from config.php to db.php.. and i had full scene infront of me . how do you think what is the best way to use db.php or config.php or both on web projects ? but i have another error. i will try to fix that error by myself..
a file with the database information is always a good idea. then you dont have to worry about going through and editing out passwords and all if you show your code to someone else to help debug. aside from that, it makes switching database servers easily. it's 4 lines (hostname,username,password,database) in 1 file instead instead of 4 lines in 100 files. as for the config.php, it depends on if you're writing the script to be released. if so, then yes, it is a good idea to make it easier on the user. if not, there's really no need as you know what everything does.