[PHP] Re: mysql_num_rows()
On 22/02/11 14:40, Gary wrote: Pete Fordp...@justcroft.com wrote in message news:76.48.39221.054c3...@pb1.pair.com... On 22/02/11 13:59, Gary wrote: Pete Fordp...@justcroft.com wrote in message news:a4.c0.39221.b3ca3...@pb1.pair.com... On 22/02/11 05:40, Gary wrote: Can someone tell me why this is not working? I do not get an error message, the results are called and echo'd to screen, the count does not work, I get a 0 for a result... $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') or die(mysql_error()); if ( isset($_POST['submit']) ) { for($i=1; $i=$_POST['counties']; $i++) { if ( isset($_POST[county$i] ) ) { echo You have chosen . $_POST[county$i].br/; } } } $county_total=mysql_num_rows($result); while($row = mysql_fetch_array($result)) {$i++; echo $row['name']; } $county_total=mysql_num_rows($result); echo $county_total; echo 'You Have ' . $county_total . ' Counties '; ? The first thing I see is that you do $county_total=mysql_num_rows($result) twice. Now I'm not to sure, but it is possible that looping over mysql_fetch_array($result) moves an array pointer so the count is not valid after the operation... that's a long shot. But since you are looping over the database records anyway, why not just count them as you go? Isn't $i the number of counties after all the looping? -- Peter Ford, Developer phone: 01580 89 fax: 01580 893399 Justcroft International Ltd. www.justcroft.com Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom Registered in England and Wales: 2297906 Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS Peter Thank you for your reply. I did notice that I had the $county_total=mysql_num_rows($result) twice. I had moved and removed it, always getting either a 0 or 1 result. I put up another test page with $result = mysql_query(SELECT * FROM `counties` ) or die(mysql_error()); $tot=mysql_num_rows($result); echo $tot; ? And it worked fine. I have tried count() as well as mysql_num_rows() but am getting the same result. Could you explain what you mean by count them as I go? Again, Thank you for your reply. Gary __ Information from ESET Smart Security, version of virus signature database 5895 (20110222) __ The message was checked by ESET Smart Security. http://www.eset.com Well, Lets go back to your original code and cut out the decoration: $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') $county_total=mysql_num_rows($result); while($row = mysql_fetch_array($result)) { echo $row['name']; } echo $county_total; That code should do pretty much what you want... But, because you only show the number of records AFTER the loop, you could do: $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') $county_total = 0; while($row = mysql_fetch_array($result)) { echo $row['name']; $county_total++; } echo $county_total; Peter Thank you for your suggestion...btw cut out the decoration LOL I'm sorry to report it did not work. I tried various configurations of it but to no avail. Any other suggestions? Again, thank you for your help. Gary __ Information from ESET Smart Security, version of virus signature database 5895 (20110222) __ The message was checked by ESET Smart Security. http://www.eset.com Gary, I'd probably need a bit more detail on the it did not work to go much further! Actually, it looks like I missed a semicolon on the mysql_query line in *both* versions - maybe that was the problem... Do you have access to your server logs, to see if any errors are reported when you run this? Cheers Peter -- Peter Ford, Developer phone: 01580 89 fax: 01580 893399 Justcroft International Ltd. www.justcroft.com Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom Registered in England and Wales: 2297906 Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_num_rows()
On 22/02/11 05:40, Gary wrote: Can someone tell me why this is not working? I do not get an error message, the results are called and echo'd to screen, the count does not work, I get a 0 for a result... $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') or die(mysql_error()); if ( isset($_POST['submit']) ) { for($i=1; $i=$_POST['counties']; $i++) { if ( isset($_POST[county$i] ) ) { echo You have chosen . $_POST[county$i].br/; } } } $county_total=mysql_num_rows($result); while($row = mysql_fetch_array($result)) {$i++; echo $row['name']; } $county_total=mysql_num_rows($result); echo $county_total; echo 'You Have ' . $county_total . ' Counties '; ? The first thing I see is that you do $county_total=mysql_num_rows($result) twice. Now I'm not to sure, but it is possible that looping over mysql_fetch_array($result) moves an array pointer so the count is not valid after the operation... that's a long shot. But since you are looping over the database records anyway, why not just count them as you go? Isn't $i the number of counties after all the looping? -- Peter Ford, Developer phone: 01580 89 fax: 01580 893399 Justcroft International Ltd. www.justcroft.com Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom Registered in England and Wales: 2297906 Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_num_rows()
Pete Ford p...@justcroft.com wrote in message news:a4.c0.39221.b3ca3...@pb1.pair.com... On 22/02/11 05:40, Gary wrote: Can someone tell me why this is not working? I do not get an error message, the results are called and echo'd to screen, the count does not work, I get a 0 for a result... $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') or die(mysql_error()); if ( isset($_POST['submit']) ) { for($i=1; $i=$_POST['counties']; $i++) { if ( isset($_POST[county$i] ) ) { echo You have chosen . $_POST[county$i].br/; } } } $county_total=mysql_num_rows($result); while($row = mysql_fetch_array($result)) {$i++; echo $row['name']; } $county_total=mysql_num_rows($result); echo $county_total; echo 'You Have ' . $county_total . ' Counties '; ? The first thing I see is that you do $county_total=mysql_num_rows($result) twice. Now I'm not to sure, but it is possible that looping over mysql_fetch_array($result) moves an array pointer so the count is not valid after the operation... that's a long shot. But since you are looping over the database records anyway, why not just count them as you go? Isn't $i the number of counties after all the looping? -- Peter Ford, Developer phone: 01580 89 fax: 01580 893399 Justcroft International Ltd. www.justcroft.com Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom Registered in England and Wales: 2297906 Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS Peter Thank you for your reply. I did notice that I had the $county_total=mysql_num_rows($result) twice. I had moved and removed it, always getting either a 0 or 1 result. I put up another test page with $result = mysql_query(SELECT * FROM `counties` ) or die(mysql_error()); $tot=mysql_num_rows($result); echo $tot; ? And it worked fine. I have tried count() as well as mysql_num_rows() but am getting the same result. Could you explain what you mean by count them as I go? Again, Thank you for your reply. Gary __ Information from ESET Smart Security, version of virus signature database 5895 (20110222) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_num_rows()
On 22/02/11 13:59, Gary wrote: Pete Fordp...@justcroft.com wrote in message news:a4.c0.39221.b3ca3...@pb1.pair.com... On 22/02/11 05:40, Gary wrote: Can someone tell me why this is not working? I do not get an error message, the results are called and echo'd to screen, the count does not work, I get a 0 for a result... $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') or die(mysql_error()); if ( isset($_POST['submit']) ) { for($i=1; $i=$_POST['counties']; $i++) { if ( isset($_POST[county$i] ) ) { echo You have chosen . $_POST[county$i].br/; } } } $county_total=mysql_num_rows($result); while($row = mysql_fetch_array($result)) {$i++; echo $row['name']; } $county_total=mysql_num_rows($result); echo $county_total; echo 'You Have ' . $county_total . ' Counties '; ? The first thing I see is that you do $county_total=mysql_num_rows($result) twice. Now I'm not to sure, but it is possible that looping over mysql_fetch_array($result) moves an array pointer so the count is not valid after the operation... that's a long shot. But since you are looping over the database records anyway, why not just count them as you go? Isn't $i the number of counties after all the looping? -- Peter Ford, Developer phone: 01580 89 fax: 01580 893399 Justcroft International Ltd. www.justcroft.com Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom Registered in England and Wales: 2297906 Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS Peter Thank you for your reply. I did notice that I had the $county_total=mysql_num_rows($result) twice. I had moved and removed it, always getting either a 0 or 1 result. I put up another test page with $result = mysql_query(SELECT * FROM `counties` ) or die(mysql_error()); $tot=mysql_num_rows($result); echo $tot; ? And it worked fine. I have tried count() as well as mysql_num_rows() but am getting the same result. Could you explain what you mean by count them as I go? Again, Thank you for your reply. Gary __ Information from ESET Smart Security, version of virus signature database 5895 (20110222) __ The message was checked by ESET Smart Security. http://www.eset.com Well, Lets go back to your original code and cut out the decoration: $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') $county_total=mysql_num_rows($result); while($row = mysql_fetch_array($result)) { echo $row['name']; } echo $county_total; That code should do pretty much what you want... But, because you only show the number of records AFTER the loop, you could do: $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') $county_total = 0; while($row = mysql_fetch_array($result)) { echo $row['name']; $county_total++; } echo $county_total; -- Peter Ford, Developer phone: 01580 89 fax: 01580 893399 Justcroft International Ltd. www.justcroft.com Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom Registered in England and Wales: 2297906 Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_num_rows()
Pete Ford p...@justcroft.com wrote in message news:76.48.39221.054c3...@pb1.pair.com... On 22/02/11 13:59, Gary wrote: Pete Fordp...@justcroft.com wrote in message news:a4.c0.39221.b3ca3...@pb1.pair.com... On 22/02/11 05:40, Gary wrote: Can someone tell me why this is not working? I do not get an error message, the results are called and echo'd to screen, the count does not work, I get a 0 for a result... $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') or die(mysql_error()); if ( isset($_POST['submit']) ) { for($i=1; $i=$_POST['counties']; $i++) { if ( isset($_POST[county$i] ) ) { echo You have chosen . $_POST[county$i].br/; } } } $county_total=mysql_num_rows($result); while($row = mysql_fetch_array($result)) {$i++; echo $row['name']; } $county_total=mysql_num_rows($result); echo $county_total; echo 'You Have ' . $county_total . ' Counties '; ? The first thing I see is that you do $county_total=mysql_num_rows($result) twice. Now I'm not to sure, but it is possible that looping over mysql_fetch_array($result) moves an array pointer so the count is not valid after the operation... that's a long shot. But since you are looping over the database records anyway, why not just count them as you go? Isn't $i the number of counties after all the looping? -- Peter Ford, Developer phone: 01580 89 fax: 01580 893399 Justcroft International Ltd. www.justcroft.com Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom Registered in England and Wales: 2297906 Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS Peter Thank you for your reply. I did notice that I had the $county_total=mysql_num_rows($result) twice. I had moved and removed it, always getting either a 0 or 1 result. I put up another test page with $result = mysql_query(SELECT * FROM `counties` ) or die(mysql_error()); $tot=mysql_num_rows($result); echo $tot; ? And it worked fine. I have tried count() as well as mysql_num_rows() but am getting the same result. Could you explain what you mean by count them as I go? Again, Thank you for your reply. Gary __ Information from ESET Smart Security, version of virus signature database 5895 (20110222) __ The message was checked by ESET Smart Security. http://www.eset.com Well, Lets go back to your original code and cut out the decoration: $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') $county_total=mysql_num_rows($result); while($row = mysql_fetch_array($result)) { echo $row['name']; } echo $county_total; That code should do pretty much what you want... But, because you only show the number of records AFTER the loop, you could do: $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') $county_total = 0; while($row = mysql_fetch_array($result)) { echo $row['name']; $county_total++; } echo $county_total; Peter Thank you for your suggestion...btw cut out the decoration LOL I'm sorry to report it did not work. I tried various configurations of it but to no avail. Any other suggestions? Again, thank you for your help. Gary __ Information from ESET Smart Security, version of virus signature database 5895 (20110222) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_num_rows
Hi John, John Taylor-Johnston wrote in message: I use $mycounter, not saying it is pretty. But if you have a whole bunch of stuff deleted, your last id might be worth a lot more than the actual number of rows. $myconnection = mysql_connect($server,$user,$pass); mysql_select_db($db,$myconnection); $news = mysql_query('select * from '.$table.' where '.$where.' order by id asc'); $mycounter = 0; while ($mydata = mysql_fetch_object($news)) { $mycounter++; } Have you ever considered just doing a count()? $count = @mysql_query(select count(*) from [table(s)] where [criteria [group by something]]); $total = mysql_result($count, 0); That will return the number of rows in your table(s). It's also much quicker and less resource intensive, particularly with large datasets. :) James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_num_rows
First, there is no reason to do mycounter like this when mysql_num_rows() will work perfectly. It's not based on any certain column numbers or primary keys. Although if you're suggesting this method to simply print 0-n in the loop (as users may want to know the row number of output not any id number) then that's good altough it's not really a counter in this case. Second, we assume this person wants a count for informational purposes, to go along with the data in which case mysql_num_rows() is your best bet. It means having a count before the data is printed/used. And checking the number or rows returned before fetching is a form of error handling as well as if it equals 0 than there is no data to fetch. But if one ONLY wants a number of rows count, doing SELECT count(*)... works great as suggested below. Regards, Philip Olson On Wed, 18 Dec 2002, liljim wrote: Hi John, John Taylor-Johnston wrote in message: I use $mycounter, not saying it is pretty. But if you have a whole bunch of stuff deleted, your last id might be worth a lot more than the actual number of rows. $myconnection = mysql_connect($server,$user,$pass); mysql_select_db($db,$myconnection); $news = mysql_query('select * from '.$table.' where '.$where.' order by id asc'); $mycounter = 0; while ($mydata = mysql_fetch_object($news)) { $mycounter++; } Have you ever considered just doing a count()? $count = @mysql_query(select count(*) from [table(s)] where [criteria [group by something]]); $total = mysql_result($count, 0); That will return the number of rows in your table(s). It's also much quicker and less resource intensive, particularly with large datasets. :) James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_num_rows
I would also tend to do a count(*) as well as the main query if I intend to use pagination (with the help of LIMIT in the main query). Suppose, for example, you're limiting to 30 news posts per page, and from calculations there are only 2 pages that fall into the criteria, then trying to bring the result set back on page 3 when it doesn't exist will result in a warning. Also, you'll want to know how many pages of the news post there are... Brief Example (assuming $page has already been validated as an integer): $num = 30; // per page $total = 49; // result from count(*) $total_pages = ceil($total/$num); if($page $total_pages) { $page = $total_pages; } // Main query. // select [whatever] from [table(s)] where [criteria] [whateverelse] limit . (($page*$num)-$num) . ,$num; James Philip Olson [EMAIL PROTECTED] wrote in message Pine.BSF.4.10.10212181637090.4483-10@localhost">news:Pine.BSF.4.10.10212181637090.4483-10@localhost... First, there is no reason to do mycounter like this when mysql_num_rows() will work perfectly. It's not based on any certain column numbers or primary keys. Although if you're suggesting this method to simply print 0-n in the loop (as users may want to know the row number of output not any id number) then that's good altough it's not really a counter in this case. Second, we assume this person wants a count for informational purposes, to go along with the data in which case mysql_num_rows() is your best bet. It means having a count before the data is printed/used. And checking the number or rows returned before fetching is a form of error handling as well as if it equals 0 than there is no data to fetch. But if one ONLY wants a number of rows count, doing SELECT count(*)... works great as suggested below. Regards, Philip Olson On Wed, 18 Dec 2002, liljim wrote: Hi John, John Taylor-Johnston wrote in message: I use $mycounter, not saying it is pretty. But if you have a whole bunch of stuff deleted, your last id might be worth a lot more than the actual number of rows. $myconnection = mysql_connect($server,$user,$pass); mysql_select_db($db,$myconnection); $news = mysql_query('select * from '.$table.' where '.$where.' order by id asc'); $mycounter = 0; while ($mydata = mysql_fetch_object($news)) { $mycounter++; } Have you ever considered just doing a count()? $count = @mysql_query(select count(*) from [table(s)] where [criteria [group by something]]); $total = mysql_result($count, 0); That will return the number of rows in your table(s). It's also much quicker and less resource intensive, particularly with large datasets. :) James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: mysql_num_rows
And now mysql4 allows doing this another way, I *assume* this new way is slightly faster then the additional count() although I haven't tested it and wonder if it affects mysql_num_rows()... See: SQL_CALC_FOUND_ROWS() http://www.mysql.com/doc/en/Miscellaneous_functions.html Regards, Philip Olson On Wed, 18 Dec 2002, liljim wrote: I would also tend to do a count(*) as well as the main query if I intend to use pagination (with the help of LIMIT in the main query). Suppose, for example, you're limiting to 30 news posts per page, and from calculations there are only 2 pages that fall into the criteria, then trying to bring the result set back on page 3 when it doesn't exist will result in a warning. Also, you'll want to know how many pages of the news post there are... Brief Example (assuming $page has already been validated as an integer): $num = 30; // per page $total = 49; // result from count(*) $total_pages = ceil($total/$num); if($page $total_pages) { $page = $total_pages; } // Main query. // select [whatever] from [table(s)] where [criteria] [whateverelse] limit . (($page*$num)-$num) . ,$num; James Philip Olson [EMAIL PROTECTED] wrote in message Pine.BSF.4.10.10212181637090.4483-10@localhost">news:Pine.BSF.4.10.10212181637090.4483-10@localhost... First, there is no reason to do mycounter like this when mysql_num_rows() will work perfectly. It's not based on any certain column numbers or primary keys. Although if you're suggesting this method to simply print 0-n in the loop (as users may want to know the row number of output not any id number) then that's good altough it's not really a counter in this case. Second, we assume this person wants a count for informational purposes, to go along with the data in which case mysql_num_rows() is your best bet. It means having a count before the data is printed/used. And checking the number or rows returned before fetching is a form of error handling as well as if it equals 0 than there is no data to fetch. But if one ONLY wants a number of rows count, doing SELECT count(*)... works great as suggested below. Regards, Philip Olson On Wed, 18 Dec 2002, liljim wrote: Hi John, John Taylor-Johnston wrote in message: I use $mycounter, not saying it is pretty. But if you have a whole bunch of stuff deleted, your last id might be worth a lot more than the actual number of rows. $myconnection = mysql_connect($server,$user,$pass); mysql_select_db($db,$myconnection); $news = mysql_query('select * from '.$table.' where '.$where.' order by id asc'); $mycounter = 0; while ($mydata = mysql_fetch_object($news)) { $mycounter++; } Have you ever considered just doing a count()? $count = @mysql_query(select count(*) from [table(s)] where [criteria [group by something]]); $total = mysql_result($count, 0); That will return the number of rows in your table(s). It's also much quicker and less resource intensive, particularly with large datasets. :) James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: mysql_num_rows
I found the problem! It was a space before $ in ' $name' in line two of the query. Sorry for the trouble. Roger -Original Message- From: Roger Lewis [mailto:[EMAIL PROTECTED]] Sent: Tuesday, December 17, 2002 4:00 PM To: Php-General Subject: mysql_num_rows Would someone be kind enough to explain why I'm not getting the correct result from the following query. If I select a valid member no. and name, the following query should return 1 row. This is not the case, however. It returns zero rows. $sql = SELECT * FROM users WHERE member_no = '$member_no' and name = ' $name' ; $result = mysql_query($sql) or die (Cannot verify the member); $rows = mysql_num_rows($result); echo rows = $rowsbr; Furthermore when trying the following query where the table users contains 13 rows, the query returns only 12 rows. $sql = SELECT * FROM users; $result = mysql_query($sql) or die (Cannot verify the member); $rows = mysql_num_rows($result); echo rows = $rowsbr; Conclusion: mysql_num_rows seems to be returning one less row than exists. Is this correct? Thanks in advance Roger Lewis -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_num_rows
I use $mycounter, not saying it is pretty. But if you have a whole bunch of stuff deleted, your last id might be worth a lot more than the actual number of rows. $myconnection = mysql_connect($server,$user,$pass); mysql_select_db($db,$myconnection); $news = mysql_query('select * from '.$table.' where '.$where.' order by id asc'); $mycounter = 0; while ($mydata = mysql_fetch_object($news)) { $mycounter++; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_num_rows error
Omar, I would first take the select statement and try running it in mysql to make sure it actually runs (substituting a valid value for the variable of course). Then if it has problems you can see what error messages mysql gives you. Good Luck, Jonathan Duncan Omar Campos [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I have a file. I'll paste from line 32 to 34 ? . $sql = select USUARIO from docente where USUARIO = '$usuario'; $result = mysql_query($sql, $link); if (mysql_num_rows($result) == 1) { // line 34 ? I get the next warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/olimpiad/public_html/base/alta1.php on line 34 I'm running the script on a linux server. could someone help me. Thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_num_rows error
In article [EMAIL PROTECTED], [EMAIL PROTECTED] says... I have a file. I'll paste from line 32 to 34 ? . $sql = select USUARIO from docente where USUARIO = '$usuario'; $result = mysql_query($sql, $link); Replace the above line with (all on one line) $result = mysql_query($sql, $link) or die(Error: . mysql_error().BRQuery: .$sql); if (mysql_num_rows($result) == 1) { // line 34 ? I get the next warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/olimpiad/public_html/base/alta1.php on line 34 I'm running the script on a linux server. could someone help me. Thank you. And when you get the error message, you will have the actual query to check. Cheers -- David Robley Temporary Kiwi! Quod subigo farinam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: mysql_num_rows
Thanks to everyone that replied. After trying solutions from everyone and still not getting it to work I finally figured out why my code: $result = mysql_query($query,$connection) or die(Error in Query); $num = mysql_num_rows($result); if ($num == 0) echo something; else echo something else; was not working. I had that piece of code in a while ($row = mysql_fetch_array($result))loop. It seems that if there is nothing to get the condition inside the while loop is false so my code above was never being executed. Even when I tried printing out the contents of $num it would always be blank. The clue came when I deliberately changed the vale of $num right above my code above and it still didn't work. Thanks again to all who replied. It was a good chance to learn about isset(), empty() and other functions. Frank Frank Miller Computer Specialist and Webmaster Technology and Distance Education Texas AM University-Texarkana 2600 North Robison Rd Texarkana, Texas 75501 Phone: 903-223-3156 Fax: 903-223-3139 Office: 165 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Mysql_num_rows
Hi Frank, I'm not exactly sure what's up with this, I've definitely used something similar before without any problems. However, maybe you can work around it by switching the logic... if($num) echo blah, blah, blah; else echo There are no events scheduled today!; Wish I had a better suggestion.. Good luck! Corey Eiseman Infinite Orange Incorporated http://infiniteorange.com/ Frank Miller [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Thanks to everyone that helped me with my last problem I've run into another problem and was wondering if someone here could offer any help or suggestions. The project I'm working on is an event calender. It does several things but the problem I've run into is when I click a date on the calendar if there are no events for that day I want to print a message on the web page saying as much. I've read the documentaion that said if I'm using a select statement to use mysql_num_rows and that it returns an integer. Here is a snippet of my code $query = SELECT *,TIME_FORMAT(eventtime, '%l:%i %p')AS eventtime, DATE_FORMAT(dateofevent,'%M %e, %Y') AS fdateofevent FROM tamutevents where refid=$refid; $result = mysql_query($query,$connection) or die(Error in Query); $num = mysql_num_rows($result); Next I say if ($num == 0) { echo There are no events scheduled today!; } else { echo blah, blah, blah; } The problem is if there are no records that match the select then it always goes to the else part. I've tried printing the value of $num and it works if there is something scheduled but when there is nothing scheduled $num shows nothing on the screen. I'm using Mysql 3.23.38 and php 4.06 on a windows test machine but it works the same on php 4.06 and Mysql 3.23.46 on my Linux server. Has anyone else run into this and if so can you tell me what to do about it. Thanks in advance - Frank Frank Miller Computer Specialist and Webmaster Technology and Distance Education Texas AM University-Texarkana 2600 North Robison Rd Texarkana, Texas 75501 Phone: 903-223-3156 Fax: 903-223-3139 Office: 165 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php