erm... hello everyone.... i am new here.... n yet, i still looking around in this forum to seek for help....
can anyone help me with this??
SQLMale ERROR");
$male = mysql_num_rows($rsMale);
?>
SQLFemale ERROR");
$female = mysql_num_rows($rsFemale);
print "";
print "";
print "Division | ";
print "Race | ";
print "Male | ";
print "Female | ";
print "Total | ";
print " ";
?>
--> i'll get this error...
--> Warning: mysql_query(): 3 is not a valid MySQL-Link resource in C:\Program Files\xampp\htdocs\my_project\member_inbenefit.php on line 58
anyone help me?? i am new to php as well..... =)
Posted by tim2718281, 06-09-2009, 09:52 PM | Which is line 58?
|
Posted by fiona_mei, 06-09-2009, 10:03 PM | ooo... i left tat out...
-->$rsMale = mysql_query($SQLMale, $dbConn) or die("SQLMale ERROR");
|
Posted by fiona_mei, 06-09-2009, 10:09 PM | forgot to mention this as well...
in my code as posted earlier...
i want to count total of members in my organisation according o their gender and division... tq...
|
Posted by tim2718281, 06-09-2009, 11:26 PM | OK, so that's giving you the error message "3 is not a valid MySQL-Link resource".
Have you looked up the documentation for mysql_query ? It's here:
http://uk.php.net/mysql_query
Presumably $dbConn is not being set correctly. So you need to look at the code that's issuing mysql_connect.
|
Posted by fiona_mei, 06-10-2009, 12:32 AM | i've been using that connection for others function... and it works well.... it just that when it comes to count function, it cannot work well.... =(
|
Posted by larwilliams, 06-10-2009, 12:42 AM | I think this is your problem:
include ("connectdb.php");
include ("closedb.php");
I assume this has the affect of opening and closing the database connection immediately.
Take "include ("closedb.php");" and move that to the end of your code
EDIT: do not include the quotes above
|
Posted by rasin, 06-10-2009, 12:48 AM | there is a line in the code
include ("closedb.php");
what it contains ?
if it contains mysql_close() statement..
then you need to change this code 'include ("closedb.php");' to bottom of the program,because mysql didnt get the pointer after the mysql_close() statement
|
Posted by fiona_mei, 06-10-2009, 01:23 AM | rasin.... it contains mysql_close...
|
Posted by fiona_mei, 06-10-2009, 01:28 AM | guys.... i love u all.... =)
i clear the error already.. but i didn't the output.... =|
|
Posted by Neseema M M, 06-10-2009, 02:02 AM | If you want to get the count of members u can give count function in sql query and take result.
Or you can give select (*) in the query and take mysql_num_rows($result).
If we are giving count function in query and return the number of rows it will be always 1.
|
Posted by fiona_mei, 06-10-2009, 04:03 AM | erm... since i am new.... i didn't get what u said... huhu.... sorry... can u xplain more...? =|
|
Posted by Neseema M M, 06-10-2009, 04:21 AM | Try below code instead of above:
Or
|
Posted by fiona_mei, 06-10-2009, 08:25 PM | neseema.... i've tried the above code.... tq =)
but i can't use this as i need to count how many members based on their gender n division...
"$SQLFemale = "SELECT (*) FROM membership WHERE gender = 'Female' AND race = '$race' AND division = '$division'";
$rsFemale = mysql_query($SQLFemale, $dbConn) or die("SQLFemale ERROR");
$female = mysql_num_rows($rsFemale);"
n i've tried the 2nd option u gave...
tis error pop out...
-->Warning: Wrong parameter count for mysql_num_rows() in C:\Program Files\xampp\htdocs\my_project\member_inbenefit.php on line 58
any other option? =|
|
Posted by Neseema M M, 06-11-2009, 12:33 AM | Sorry... there is no need of '()' around '*'. So remove that braces.
Try like this:
|
Posted by fiona_mei, 06-11-2009, 02:19 AM | as far as i concern...
select *from will retrieve all the data... not count the data....
is tat right?
|
Posted by Neseema M M, 06-11-2009, 02:47 AM | You will get the count of data using the function mysql_num_rows().
Or
Make sure referer field exists in the db.
|
Posted by fiona_mei, 06-11-2009, 08:30 PM | Neseema...
i am glad tat i learnt a lot from u... =)
but....
i still can't get the ans.... huhu.....=|
|
Posted by larwilliams, 06-11-2009, 08:37 PM | Is all that code in one file? If so, it won't work. Put the HTML stuff in one file and the PHP code in a second file, and update the |
Posted by fiona_mei, 06-11-2009, 10:07 PM | hmmm.... yeap... 1 file....
i oso do other function under 1 file... but it works well....
|
Posted by foobic, 06-11-2009, 11:05 PM | Apart from that, the code is wide open to SQL injection - it would be dangerous to open it to the public until you fix this. As a general rule, always sanitize user inputs as soon as you can. eg. If your "in_benefit" input can only take the values "A", "N" or "Y", you could use:
(for extra brownie points, loop through the values in the array to create the select options)
|
Posted by fiona_mei, 06-12-2009, 02:37 AM | haha... am so happy.... i finally can count the members... without everyone help, i could have failed.... =)
hehe..... erm.... then how can i display the data in the table?
my table--> |division | race | male | female | total |
can anyone help me? =)
|
Add to Favourites Print this Article
Also Read
|