Re: [PHP-DB] mysql_num_rows == 0
On 30 May 2011 22:31, Nazish naz...@jhu.edu wrote: Hi all, I've run into a little barrier, and I'm wondering whether you have any insights. I'm entering values into a MySQL database. Before running the mysql_query, I'm checking if the value already exists (using mysql_num_rows == 0). If the value already exists in the database, the page will echo Username already exists and it won't insert the user's new value. It runs that far, and echoes the message accordingly. However, if the username is new, and does not exist in the database, the query dies (without leaving a mysql error). I tried changing the Unique IDs in the database, but it doesn't seem to be the issue. The syntax seems fine, as I used it for another similar page. Any idea why it's dying? $check = mysql_query(SELECT * FROM user WHERE user_name='$user_name') or die (Unable to query database:.mysql_error()); $numrows = mysql_num_rows($check) or die (Unable to search database:.mysql_error()); - DIES HERE when a new value is entered. no mysql_error msg. bla bla or die(more bla); is a very bad way of handling error checks. In your particular case, your foot has been shot off because mysql_num_rows will return 0 (no rows match the query) and thus the die() is executed - but of course there's no error in the query, it executed just fine, this we know already. Moral: don't use ' or die();' for anything else than hands on debugging purposes Regards Peter -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows == 0
try this instead.. if(mysql_num_rows($check) 0) { //true } else { //false } and yes, Peter's right... please dont make everything die(). Karl On May 30, 2011, at 3:43 PM, Peter Lind wrote: On 30 May 2011 22:31, Nazish naz...@jhu.edu wrote: Hi all, I've run into a little barrier, and I'm wondering whether you have any insights. I'm entering values into a MySQL database. Before running the mysql_query, I'm checking if the value already exists (using mysql_num_rows == 0). If the value already exists in the database, the page will echo Username already exists and it won't insert the user's new value. It runs that far, and echoes the message accordingly. However, if the username is new, and does not exist in the database, the query dies (without leaving a mysql error). I tried changing the Unique IDs in the database, but it doesn't seem to be the issue. The syntax seems fine, as I used it for another similar page. Any idea why it's dying? $check = mysql_query(SELECT * FROM user WHERE user_name='$user_name') or die (Unable to query database:.mysql_error()); $numrows = mysql_num_rows($check) or die (Unable to search database:.mysql_error()); - DIES HERE when a new value is entered. no mysql_error msg. bla bla or die(more bla); is a very bad way of handling error checks. In your particular case, your foot has been shot off because mysql_num_rows will return 0 (no rows match the query) and thus the die() is executed - but of course there's no error in the query, it executed just fine, this we know already. Moral: don't use ' or die();' for anything else than hands on debugging purposes Regards Peter -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows == 0
That did the trick: I was over-enthusiastic in my usage of die(mysql_error). I initially used mysql_error to troubleshoot another problem (which has now re-emerged), but that's a different question which is puzzling me. The error message ($alert = Username already exists!;) displays on the page as soon as the value has been inserted into mysql. It's strange, since the message should be bypassed through the else statement, and the script only runs if the user clicks 'submit'. Is this familiar? $check = mysql_query(SELECT * FROM user WHERE user_name='$user_name') or die (Unable to query database:.mysql_error()); $numrows = mysql_num_rows($check) or die (Unable to search database:.mysql_error()); - DIES HERE when a new value is entered. no mysql_error msg. bla bla or die(more bla); is a very bad way of handling error checks. In your particular case, your foot has been shot off because mysql_num_rows will return 0 (no rows match the query) and thus the die() is executed - but of course there's no error in the query, it executed just fine, this we know already. Moral: don't use ' or die();' for anything else than hands on debugging purposes Regards Peter 2011/5/30 Peter Lind peter.e.l...@gmail.com On 30 May 2011 22:31, Nazish naz...@jhu.edu wrote: Hi all, I've run into a little barrier, and I'm wondering whether you have any insights. I'm entering values into a MySQL database. Before running the mysql_query, I'm checking if the value already exists (using mysql_num_rows == 0). If the value already exists in the database, the page will echo Username already exists and it won't insert the user's new value. It runs that far, and echoes the message accordingly. However, if the username is new, and does not exist in the database, the query dies (without leaving a mysql error). I tried changing the Unique IDs in the database, but it doesn't seem to be the issue. The syntax seems fine, as I used it for another similar page. Any idea why it's dying? $check = mysql_query(SELECT * FROM user WHERE user_name='$user_name') or die (Unable to query database:.mysql_error()); $numrows = mysql_num_rows($check) or die (Unable to search database:.mysql_error()); - DIES HERE when a new value is entered. no mysql_error msg. bla bla or die(more bla); is a very bad way of handling error checks. In your particular case, your foot has been shot off because mysql_num_rows will return 0 (no rows match the query) and thus the die() is executed - but of course there's no error in the query, it executed just fine, this we know already. Moral: don't use ' or die();' for anything else than hands on debugging purposes Regards Peter -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype
Re: [PHP-DB] mysql_num_rows == 0
Code runs smoothly now, thanks. It's always great to pick up diverse coding tips through the conversations here. 2011/5/30 Nazish naz...@jhu.edu That did the trick: I was over-enthusiastic in my usage of die(mysql_error). I initially used mysql_error to troubleshoot another problem (which has now re-emerged), but that's a different question which is puzzling me. The error message ($alert = Username already exists!;) displays on the page as soon as the value has been inserted into mysql. It's strange, since the message should be bypassed through the else statement, and the script only runs if the user clicks 'submit'. Is this familiar? $check = mysql_query(SELECT * FROM user WHERE user_name='$user_name') or die (Unable to query database:.mysql_error()); $numrows = mysql_num_rows($check) or die (Unable to search database:.mysql_error()); - DIES HERE when a new value is entered. no mysql_error msg. bla bla or die(more bla); is a very bad way of handling error checks. In your particular case, your foot has been shot off because mysql_num_rows will return 0 (no rows match the query) and thus the die() is executed - but of course there's no error in the query, it executed just fine, this we know already. Moral: don't use ' or die();' for anything else than hands on debugging purposes Regards Peter 2011/5/30 Peter Lind peter.e.l...@gmail.com On 30 May 2011 22:31, Nazish naz...@jhu.edu wrote: Hi all, I've run into a little barrier, and I'm wondering whether you have any insights. I'm entering values into a MySQL database. Before running the mysql_query, I'm checking if the value already exists (using mysql_num_rows == 0). If the value already exists in the database, the page will echo Username already exists and it won't insert the user's new value. It runs that far, and echoes the message accordingly. However, if the username is new, and does not exist in the database, the query dies (without leaving a mysql error). I tried changing the Unique IDs in the database, but it doesn't seem to be the issue. The syntax seems fine, as I used it for another similar page. Any idea why it's dying? $check = mysql_query(SELECT * FROM user WHERE user_name='$user_name') or die (Unable to query database:.mysql_error()); $numrows = mysql_num_rows($check) or die (Unable to search database:.mysql_error()); - DIES HERE when a new value is entered. no mysql_error msg. bla bla or die(more bla); is a very bad way of handling error checks. In your particular case, your foot has been shot off because mysql_num_rows will return 0 (no rows match the query) and thus the die() is executed - but of course there's no error in the query, it executed just fine, this we know already. Moral: don't use ' or die();' for anything else than hands on debugging purposes Regards Peter -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype
[PHP-DB] mysql_num_rows, resource id #
In my code below, I am trying to verify that the query is selecting data from both rows of my answers table. I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0. I can't figure out why its not returning 2 for the number of rows. It is not giving me any error msgs such as cannot connect. Also can tell me where I can find documentation on resource id #, such as resource(5)? ?PHP DEFINE (host,localhost); DEFINE (user,root); DEFINE (password,pasword); DEFINE (database,questions); $connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() ); $dbConnect=mysql_select_db('questions',$connection); if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );} $result = mysql_query(Select answer from answers where studentID='A123456789') or die(mysql_error()); $rows = mysql_num_rows($result); echo $rows; ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows, resource id #
Richard Dunne wrote: In my code below, I am trying to verify that the query is selecting data from both rows of my answers table. I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0. I can't figure out why its not returning 2 for the number of rows. It is not giving me any error msgs such as cannot connect. Also can tell me where I can find documentation on resource id #, such as resource(5)? ?PHP DEFINE (host,localhost); DEFINE (user,root); DEFINE (password,pasword); DEFINE (database,questions); $connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() ); $dbConnect=mysql_select_db('questions',$connection); if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );} $result = mysql_query(Select answer from answers where studentID='A123456789') or die(mysql_error()); $rows = mysql_num_rows($result); echo $rows; ? Still no luck then. Try selecting the DB without the connection parameter: $dbConnect=mysql_select_db('questions'); And don't forget to set error_reporting(E_ALL) above your code. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Fwd: Re: [PHP-DB] mysql_num_rows, resource id #
This much is working: ?PHP ini_set('error_reporting',E_All); DEFINE (host,localhost); DEFINE (user,root); DEFINE (password,password); DEFINE (database,questions); $connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() ); $dbConnect=mysql_select_db('questions'); if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );} $result = mysql_query(Select answer from answers where studentID='A123456789') or die(mysql_error()); $rows = mysql_num_rows($result); echo $rows . \n; $answer = mysql_fetch_row($result); foreach($answer as $a) { echo $a; } ? The output is 1 1 which is correct. One small step at a time, hopefully forward. Richard. ---BeginMessage--- Richard Dunne wrote: In my code below, I am trying to verify that the query is selecting data from both rows of my answers table. I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0. I can't figure out why its not returning 2 for the number of rows. It is not giving me any error msgs such as cannot connect. Also can tell me where I can find documentation on resource id #, such as resource(5)? ?PHP DEFINE (host,localhost); DEFINE (user,root); DEFINE (password,pasword); DEFINE (database,questions); $connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() ); $dbConnect=mysql_select_db('questions',$connection); if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );} $result = mysql_query(Select answer from answers where studentID='A123456789') or die(mysql_error()); $rows = mysql_num_rows($result); echo $rows; ? Still no luck then. Try selecting the DB without the connection parameter: $dbConnect=mysql_select_db('questions'); And don't forget to set error_reporting(E_ALL) above your code. ---End Message--- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql_num_rows
Dear Sir or Madame, I found the following error, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/xxx/public_html/sitename/dynamicfile.php on line 61 What is the reason? I want anyone who knows to answer to reply me. Thank you in advance for sharing your precious time. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
That means that you dont have any rows to work with. It could mean that you are not connected to the database, or the query you performed did not return any rows. Calvin On Tue, 8 Mar 2005 16:11:10 +0300, Tsegaye Woldegebriel [EMAIL PROTECTED] wrote: Dear Sir or Madame, I found the following error, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/xxx/public_html/sitename/dynamicfile.php on line 61 What is the reason? I want anyone who knows to answer to reply me. Thank you in advance for sharing your precious time. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
Use the mysql_error() function which may give you more answers. In addition you can use something like $num = mysql_num_rows($test); echo $num; If it returns 0 you have no entries, if nothing happens then you have problem with your query or connection. If you get a number then there is something else wrong. This is a test I haa to use to sort out some code. It is best if you use mysql_error() whenever possible during testing so that you can know exactly what goes wrong where. But I am a noob. There are probaly others with better answers. Tsegaye Woldegebriel wrote: Dear Sir or Madame, I found the following error, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/xxx/public_html/sitename/dynamicfile.php on line 61 What is the reason? I want anyone who knows to answer to reply me. Thank you in advance for sharing your precious time. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
Calvin Lough wrote: That means that you dont have any rows to work with. It could mean that you are not connected to the database, or the query you performed did not return any rows. Calvin On Tue, 8 Mar 2005 16:11:10 +0300, Tsegaye Woldegebriel [EMAIL PROTECTED] wrote: Dear Sir or Madame, I found the following error, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/xxx/public_html/sitename/dynamicfile.php on line 61 What is the reason? I want anyone who knows to answer to reply me. Thank you in advance for sharing your precious time. Just to clarify - you won't get this error if a valid SQL query is performed and it returns no rows. This means just what it says - the argument passed to it is not the result of a valid SQL query that has been executed on the server. (note: result of a query, not the query itself - it should print_r as a number not as a select blah - it's a result resource, a pointer of sorts). More likely is the query is invalid, go ahead and print_r() the variable being passed to mysql_num_rows() on line 61 (put it before the mysql_num_rows call) and see what info you get back in there. cheers, -- - Martin Norland, Sys Admin / Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql_num_rows
Perhaps someone could look at this function and help me trouble shoot it? This function notifies the user of their new passwd. I keep getting an error message on this page (see below). What's strange is the script seems to be working because i am getting an email with my new password. Here is the error message I am receiving: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 70 suggestions? Anything will be helpful. Much Thanks CH function notify_password($username, $password) // notify the user that their password has been changed { $query =SELECT username FROM users WHERE username=('$username'); // $result = mysql_query($query, $db); if (!$query) { return false; // not changed } line 70 = else if (mysql_num_rows($query)==1) $user_id = mysql_result($query, 0, 'user_id'); $from = From: [EMAIL PROTECTED] \r\n; $mesg = Your password has been changed to $password \r\n .You might want to change it next time you log in. \r\n; if (mail($username, 'Cyclists Edge login information', $mesg, $from)) return true; else return false; } __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] mysql_num_rows
From a quick glance, I noticed that you have commented out the code that does the actual query against the MySQL database. This is the line: // $result = mysql_query($query, $db); Without this statement, there is no query to the database. It should be: $result = mysql_query($query); //without specifying a database link, it will use the available one The $result variable will then hold a result identifier that should be used throughout your code from then on (i.e. any place you currently have $query). For example: mysql_num_rows($result) or mysql_result($result, 0, 'user_id'); --Nicole --- Nicole Swan Web Programming Specialist Carroll College CCIT (406)447-4310 -Original Message- From: Craig Hoffman [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 03, 2004 12:50 PM To: [EMAIL PROTECTED] Subject: Spam:[PHP-DB] mysql_num_rows Perhaps someone could look at this function and help me trouble shoot it? This function notifies the user of their new passwd. I keep getting an error message on this page (see below). What's strange is the script seems to be working because i am getting an email with my new password. Here is the error message I am receiving: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 70 suggestions? Anything will be helpful. Much Thanks CH function notify_password($username, $password) // notify the user that their password has been changed { $query =SELECT username FROM users WHERE username=('$username'); // $result = mysql_query($query, $db); if (!$query) { return false; // not changed } line 70 = else if (mysql_num_rows($query)==1) $user_id = mysql_result($query, 0, 'user_id'); $from = From: [EMAIL PROTECTED] \r\n; $mesg = Your password has been changed to $password \r\n .You might want to change it next time you log in. \r\n; if (mail($username, 'Cyclists Edge login information', $mesg, $from)) return true; else return false; } __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
because you're supplying it with a string not the result of the query.. uncomment your line that says: $result = mysql_query($query, $db); and change the num rows line to: else if (mysql_num_rows($result)==1) Your line that gets the column results will fail for the same reason, give it the result of the query, not the query itself. -Micah On Wednesday 03 March 2004 11:50 am, Craig Hoffman wrote: Perhaps someone could look at this function and help me trouble shoot it? This function notifies the user of their new passwd. I keep getting an error message on this page (see below). What's strange is the script seems to be working because i am getting an email with my new password. Here is the error message I am receiving: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 70 suggestions? Anything will be helpful. Much Thanks CH function notify_password($username, $password) // notify the user that their password has been changed { $query =SELECT username FROM users WHERE username=('$username'); // $result = mysql_query($query, $db); if (!$query) { return false; // not changed } line 70 = else if (mysql_num_rows($query)==1) $user_id = mysql_result($query, 0, 'user_id'); $from = From: [EMAIL PROTECTED] \r\n; $mesg = Your password has been changed to $password \r\n .You might want to change it next time you log in. \r\n; if (mail($username, 'Cyclists Edge login information', $mesg, $from)) return true; else return false; } __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
$query =SELECT username FROM users WHERE username=('$username'); // $result = mysql_query($query, $db); Above line should be uncommented. if (!$query) And the if checking the number of rows returned from the $result set. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
ok, I uncommented the line and changed a few things around. However I am still getting errors. I really do appreciate everyone's help. Thanks CH Here is the 'new' code: function notify_password($username, $password) // notify the user that their password has been changed { $query =SELECT username FROM users WHERE username=('$username'); = line 65 $result = mysql_query($query, $db); if (!$query) { return false; // not changed } = line 70 else if (mysql_num_rows($result)==1) $user_id = mysql_result($result, 0, 'user_id'); $from = From: [EMAIL PROTECTED] \r\n; $mesg = Your password has been changed to $password \r\n .You might want to change it next time you log in. \r\n; if (mail($username, 'Cyclists Edge login information', $mesg, $from)) return true; else return false; } Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 65 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 70 Your new password has been sent to your email address. __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 3, 2004, at 2:17 PM, Daniel Clark wrote: $query =SELECT username FROM users WHERE username=('$username'); // $result = mysql_query($query, $db); Above line should be uncommented. if (!$query) And the if checking the number of rows returned from the $result set. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] mysql_num_rows
Craig, First off, where is the $db variable being set? You include it in: $result = mysql_query($query, $db); which is line 65, but, according to your function, it's not passed into the function as an argument and I don't see you setting $db equal to anything inside the function. Second, why are you checking if(!$query)? You set $query to the string $query =SELECT username FROM users WHERE username=('$username'); so why would it never NOT be set? Maybe you mean to check to see if the query produced any results? In which case you should probably be checking if(!$results). Additionally, you should probably add an or die(mysql_error()) after your mysql_query... line to display errors from the database. And if your query process fails at line 65 because $db isn't defined, then line 70 won't work because you haven't performed a query to return any rows. Hope this helps. Rich -Original Message- From: Craig Hoffman [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 03, 2004 3:34 PM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] mysql_num_rows ok, I uncommented the line and changed a few things around. However I am still getting errors. I really do appreciate everyone's help. Thanks CH Here is the 'new' code: function notify_password($username, $password) // notify the user that their password has been changed { $query =SELECT username FROM users WHERE username=('$username'); = line 65$result = mysql_query($query, $db); if (!$query) { return false; // not changed } = line 70else if (mysql_num_rows($result)==1) $user_id = mysql_result($result, 0, 'user_id'); $from = From: [EMAIL PROTECTED] \r\n; $mesg = Your password has been changed to $password \r\n .You might want to change it next time you log in. \r\n; if (mail($username, 'Cyclists Edge login information', $mesg, $from)) return true; else return false; } Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 65 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 70 Your new password has been sent to your email address. __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 3, 2004, at 2:17 PM, Daniel Clark wrote: $query =SELECT username FROM users WHERE username=('$username'); // $result = mysql_query($query, $db); Above line should be uncommented. if (!$query) And the if checking the number of rows returned from the $result set. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
the $db variable isn't referencing a proper connection. As you did not create the db connection in this function, I'm assuming it's a scope problem. Make sure that $db is global, and then add a global statement to the first line in the function for this variable. the $db you're referencing in the query is not the same $db that you assigned the connection parameter to. If you're a sloppy programmer like me, and you only have 1 connection, you can eliminate it from the query statement if you want. -Micah On Wednesday 03 March 2004 12:33 pm, Craig Hoffman wrote: ok, I uncommented the line and changed a few things around. However I am still getting errors. I really do appreciate everyone's help. Thanks CH Here is the 'new' code: function notify_password($username, $password) // notify the user that their password has been changed { $query =SELECT username FROM users WHERE username=('$username'); = line 65$result = mysql_query($query, $db); if (!$query) { return false; // not changed } = line 70else if (mysql_num_rows($result)==1) $user_id = mysql_result($result, 0, 'user_id'); $from = From: [EMAIL PROTECTED] \r\n; $mesg = Your password has been changed to $password \r\n .You might want to change it next time you log in. \r\n; if (mail($username, 'Cyclists Edge login information', $mesg, $from)) return true; else return false; } Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 65 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 70 Your new password has been sent to your email address. __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 3, 2004, at 2:17 PM, Daniel Clark wrote: $query =SELECT username FROM users WHERE username=('$username'); // $result = mysql_query($query, $db); Above line should be uncommented. if (!$query) And the if checking the number of rows returned from the $result set. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
I got it working! Thanks everyone! __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 3, 2004, at 2:46 PM, Micah Stevens wrote: the $db variable isn't referencing a proper connection. As you did not create the db connection in this function, I'm assuming it's a scope problem. Make sure that $db is global, and then add a global statement to the first line in the function for this variable. the $db you're referencing in the query is not the same $db that you assigned the connection parameter to. If you're a sloppy programmer like me, and you only have 1 connection, you can eliminate it from the query statement if you want. -Micah On Wednesday 03 March 2004 12:33 pm, Craig Hoffman wrote: ok, I uncommented the line and changed a few things around. However I am still getting errors. I really do appreciate everyone's help. Thanks CH Here is the 'new' code: function notify_password($username, $password) // notify the user that their password has been changed { $query =SELECT username FROM users WHERE username=('$username'); = line 65 $result = mysql_query($query, $db); if (!$query) { return false; // not changed } = line 70 else if (mysql_num_rows($result)==1) $user_id = mysql_result($result, 0, 'user_id'); $from = From: [EMAIL PROTECTED] \r\n; $mesg = Your password has been changed to $password \r\n .You might want to change it next time you log in. \r\n; if (mail($username, 'Cyclists Edge login information', $mesg, $from)) return true; else return false; } Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 65 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Users/choffman/Sites/www/cyclistsedge/include/ forgot_password_functions.php on line 70 Your new password has been sent to your email address. __ Craig Hoffman - eClimb Media v: (847) 644 - 8914 f: (847) 866 - 1946 e: [EMAIL PROTECTED] w: www.eclimb.net _ On Mar 3, 2004, at 2:17 PM, Daniel Clark wrote: $query =SELECT username FROM users WHERE username=('$username'); // $result = mysql_query($query, $db); Above line should be uncommented. if (!$query) And the if checking the number of rows returned from the $result set. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql_num_rows()
Hi, I have been having some trouble with this, I mysql_num_rows() to find out how many rows there are and do an insert statement in the for loop for every row returned. So, if mysql_num_rows returns 17 then the for loops does an insert statement for every instance, when the 17 turns into zero the loop stops. For some reason the $insert never recieves any value. Thanks in advance, Tyler Whitesides East Valley School District WebAdministrator -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows()
On Wednesday 20 November 2002 09:11, Tyler Whitesides wrote: Hi, I have been having some trouble with this, I mysql_num_rows() to find out how many rows there are and do an insert statement in the for loop for every row returned. So, if mysql_num_rows returns 17 then the for loops does an insert statement for every instance, when the 17 turns into zero the loop stops. For some reason the $insert never recieves any value. Please post your code. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* I don't believe there really IS a GAS SHORTAGE.. I think it's all just a BIG HOAX on the part of the plastic sign salesmen -- to sell more numbers!! */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql_num_rows
I'm getting a strange error message from calling this function It spits out Unknown column 'Resource' in 'field List' This is my query: SELECT dept.name, count(maintenance.deptid)/$total AS percentage FROM maintenance JOIN dept WHERE maintenance.deptid=dept.deptid GROUP BY dept.name This query runs fine in console I just can't get mysql_num_rows to return a value. This is running mysql 4.0.3 and php 4.2.3 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql_num_rows
I'm getting a strange error message from calling this function It spits out Unknown column 'Resource' in 'field List' This is my query: SELECT dept.name, count(maintenance.deptid)/$total AS percentage FROM maintenance JOIN dept WHERE maintenance.deptid=dept.deptid GROUP BY dept.name This query runs fine in console I just can't get mysql_num_rows to return a value. This is running mysql 4.0.3 and php 4.2.3 What's the value of $total? Probably Resource, meaning something else before you query isn't going as you expect it to. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
FW: [PHP-DB] mysql_num_rows
-- From: 1LT John W. Holmes [SMTP:[EMAIL PROTECTED]] mailto:[SMTP:[EMAIL PROTECTED]] Sent: Thursday, September 19, 2002 2:56 PM To: LSC Exhibits Department; [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Subject: Re: [PHP-DB] mysql_num_rows What's the value of $total? Probably Resource, meaning something else before you query isn't going as you expect it to. Yep that was what is was I put single quotation marks around $total and solved that prolem Thanks John Coder -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql_num_rows
Hello All, I am struggling to understand why my query throws an error the code as below $link = mysql_connect ( db.localhost.org, $user , $pass ); if ( ! $link ) die ( Couldn't Connect to Mysql Server ); print Sucessfully connect to server p; $query = select * from users .where screen_name='$screen_name' . and passwd=password('$passwd'); $result = mysql_query($query, $link); if (mysql_num_rows($result) 0 ) When executed you get a little message back like this one Warning: Supplied argument is not a valid MySQL result resource in /usr/local/share/doc/apache/trial/authmain.php on line 20 What does this generally mean as I have noted that others use this syntax so what is my issue ? Any help or pointers to references would be most appreciated. Thanks Luke K -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] mysql_num_rows
-Original Message- From: Gurhan Ozen [mailto:[EMAIL PROTECTED]] Sent: 06 January 2002 20:10 I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); snip The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. Have you echoed $result to see what it contains? My guess is that it contains something unexpected which, when inserted into the query, causes it to fail (or at least return no rows!). Otherwise, I can see no reason for the addition of the WHERE clause to cause this error. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] mysql_num_rows
don't know if this makes a difference, but i've always used WHERE bookid = '$bookid'; - single quote round the $bookid variable - not sure if that's the problem, or if it's just good practice? -Original Message- From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED]] Sent: 08 January 2002 14:07 To: 'Gurhan Ozen'; [EMAIL PROTECTED] Subject: RE: [PHP-DB] mysql_num_rows -Original Message- From: Gurhan Ozen [mailto:[EMAIL PROTECTED]] Sent: 06 January 2002 20:10 I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); snip The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. Have you echoed $result to see what it contains? My guess is that it contains something unexpected which, when inserted into the query, causes it to fail (or at least return no rows!). Otherwise, I can see no reason for the addition of the WHERE clause to cause this error. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.312 / Virus Database: 173 - Release Date: 31/12/01 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.312 / Virus Database: 173 - Release Date: 31/12/01 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] mysql_num_rows
-Original Message- From: Gurhan Ozen [mailto:[EMAIL PROTECTED]] Sent: 06 January 2002 20:10 I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); snip The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. Have you echoed $result to see what it contains? My guess is Sorry, that should be $bookid...!! that it contains something unexpected which, when inserted into the query, causes it to fail (or at least return no rows!). Otherwise, I can see no reason for the addition of the WHERE clause to cause this error. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] mysql_num_rows
-Original Message- From: matt stewart [mailto:[EMAIL PROTECTED]] Sent: 08 January 2002 14:10 don't know if this makes a difference, but i've always used WHERE bookid = '$bookid'; - single quote round the $bookid variable - not sure if that's the problem, or if it's just good practice? Depends on whether $bookid is a string or a number. If your id values are always numeric, there's really no point in quoting them in the query. On the other hand, if they can be strings it's pretty vital to quote them!! Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] mysql_num_rows
dont u need to add the $sql to the mysql_query... as in mysql_query($sql,$db); ?? i thourhgt u did ? anyways.. might be wrong. Neil - Original Message - From: Ford, Mike [LSS] [EMAIL PROTECTED] To: 'Gurhan Ozen' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, January 08, 2002 6:07 AM Subject: RE: [PHP-DB] mysql_num_rows -Original Message- From: Gurhan Ozen [mailto:[EMAIL PROTECTED]] Sent: 06 January 2002 20:10 I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); snip The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. Have you echoed $result to see what it contains? My guess is that it contains something unexpected which, when inserted into the query, causes it to fail (or at least return no rows!). Otherwise, I can see no reason for the addition of the WHERE clause to cause this error. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] mysql_num_rows
Drop the $result from the mysql_num_rows() so it reads: $num_results=mysql_num_rows(); Depending upon the PHP version, that might do the trick for you. kind regards, bill Mike Ford wrote: -Original Message- From: Gurhan Ozen [mailto:[EMAIL PROTECTED]] Sent: 06 January 2002 20:10 I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); snip The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. Have you echoed $result to see what it contains? My guess is that it contains something unexpected which, when inserted into the query, causes it to fail (or at least return no rows!). Otherwise, I can see no reason for the addition of the WHERE clause to cause this error. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] mysql_num_rows
It would help if we could see the actual query. It sounds like the problem is a syntax error in the query itself. At 11:52 AM 1/6/2002, Gurhan Ozen wrote: Hi everyone, I have a problem with mysql connectivety which is making me nuts. If the query is select blah, blah from table (i.e. without where clause) mysql_num_rows returns the right number, but when i put in a query with where clause, although there are rows returned, PHP is giving: Warning: Supplied argument is not a valid MySQL result resource error.. Can anyone point me to any direction about this? Thanks. Gurhan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] Sliante, Richard S. Crawford http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford MSN: [EMAIL PROTECTED] It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] mysql_num_rows
I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); I have loaded a book into the tabel called books. I have gave each section a nodeid and each book a bookid. SO i wanted to get number of distinct nodeid's (i.e. sections) in the book so that i could use a for loop to display all of them and an inner for loop to display each page under each section. The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. By the way the web hoster i am using has PHP Version 4.0.6 . Thanks. Gurhan -Original Message- From: Richard S. Crawford [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 06, 2002 3:01 PM To: Gurhan Ozen; [EMAIL PROTECTED] Subject: Re: [PHP-DB] mysql_num_rows It would help if we could see the actual query. It sounds like the problem is a syntax error in the query itself. At 11:52 AM 1/6/2002, Gurhan Ozen wrote: Hi everyone, I have a problem with mysql connectivety which is making me nuts. If the query is select blah, blah from table (i.e. without where clause) mysql_num_rows returns the right number, but when i put in a query with where clause, although there are rows returned, PHP is giving: Warning: Supplied argument is not a valid MySQL result resource error.. Can anyone point me to any direction about this? Thanks. Gurhan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] Sliante, Richard S. Crawford http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford MSN: [EMAIL PROTECTED] It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] mysql_num_rows
Hm, if the result you want is the number of distinct nodeid values, why not use a query like this: select count(distinct(nodeid)) as nodecount from books where bookid = $bookid; Then the number of nodeid's is stored in nodecount. You might also want to look into the GROUP BY clause. That might give you a better handle on what you want to do. At 12:09 PM 1/6/2002, Gurhan Ozen wrote: I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); I have loaded a book into the tabel called books. I have gave each section a nodeid and each book a bookid. SO i wanted to get number of distinct nodeid's (i.e. sections) in the book so that i could use a for loop to display all of them and an inner for loop to display each page under each section. The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. By the way the web hoster i am using has PHP Version 4.0.6 . Thanks. Gurhan Sliante, Richard S. Crawford http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford MSN: [EMAIL PROTECTED] It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] mysql_num_rows
hmm that's an idea... I stil don't get why mysql_num_rows wouldn't work with WHERE clause but i will try to do a workaround with what you said below. Although it will be a little extra coding I guess I don't have any other choice:) Thank you very much for your help:) Gurhan -Original Message- From: Richard S. Crawford [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 06, 2002 3:34 PM To: Gurhan Ozen; [EMAIL PROTECTED] Subject: RE: [PHP-DB] mysql_num_rows Hm, if the result you want is the number of distinct nodeid values, why not use a query like this: select count(distinct(nodeid)) as nodecount from books where bookid = $bookid; Then the number of nodeid's is stored in nodecount. You might also want to look into the GROUP BY clause. That might give you a better handle on what you want to do. At 12:09 PM 1/6/2002, Gurhan Ozen wrote: I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); I have loaded a book into the tabel called books. I have gave each section a nodeid and each book a bookid. SO i wanted to get number of distinct nodeid's (i.e. sections) in the book so that i could use a for loop to display all of them and an inner for loop to display each page under each section. The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. By the way the web hoster i am using has PHP Version 4.0.6 . Thanks. Gurhan Sliante, Richard S. Crawford http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford MSN: [EMAIL PROTECTED] It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] mysql_num_rows
Gurhan, The first rule with all of these problems is to insert error-checking statements. There are two types: firstly the MySQL function set includes error number and error (msg) text facilities; and secondly the addition of 'debug' echo statements, eg to be absolutely sure what $query looks like before it gets fed to MySQL. The other advice is to copy the $query text into a MySQL command line or an administrative package, eg MySQL-Front, to test if it works in 'native' mode (so then you can work out if the source of the problem is PHP or MySQL code). Regards, =dn - Original Message - From: Gurhan Ozen [EMAIL PROTECTED] To: Richard S. Crawford [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: 06 January 2002 20:42 Subject: RE: [PHP-DB] mysql_num_rows hmm that's an idea... I stil don't get why mysql_num_rows wouldn't work with WHERE clause but i will try to do a workaround with what you said below. Although it will be a little extra coding I guess I don't have any other choice:) Thank you very much for your help:) Gurhan -Original Message- From: Richard S. Crawford [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 06, 2002 3:34 PM To: Gurhan Ozen; [EMAIL PROTECTED] Subject: RE: [PHP-DB] mysql_num_rows Hm, if the result you want is the number of distinct nodeid values, why not use a query like this: select count(distinct(nodeid)) as nodecount from books where bookid = $bookid; Then the number of nodeid's is stored in nodecount. You might also want to look into the GROUP BY clause. That might give you a better handle on what you want to do. At 12:09 PM 1/6/2002, Gurhan Ozen wrote: I am pretty sure that the query is correct. here is the actual query: $query=select distinct(nodeid), nodename from books where bookid=$bookid; $result=mysql_query($query); $num_results=mysql_num_rows($result); I have loaded a book into the tabel called books. I have gave each section a nodeid and each book a bookid. SO i wanted to get number of distinct nodeid's (i.e. sections) in the book so that i could use a for loop to display all of them and an inner for loop to display each page under each section. The funny thing is that if i write the same query without where bookid=$bookid then the mysql_num_rows works but with where statement it doesn't. By the way the web hoster i am using has PHP Version 4.0.6 . Thanks. Gurhan Sliante, Richard S. Crawford http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford MSN: [EMAIL PROTECTED] It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]