Web Hosting Talk







View Full Version : $15 - MySQL Error (Auction Script)


NuPixel
12-03-2005, 09:52 AM
Thank you for reading this post. I have an auction script but it keeps giving me this error when I try to run it:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/auction.site.com/httpdocs/index.php on line 304

site = my domain name
Here is what line 304 looks like:
$num_auction = mysql_num_rows($result);

I am offering $15 Dollars to the first person who fixes this problem. If its fixed in 24hr, you will receive $20 USD via PayPal.
You can contact me on AIM or MSN, or you can email me: Contact [ at ] NuPixel.com
Thank you

jimlundeen
12-03-2005, 10:31 AM
Please copy and paste the mysql query that was sent just before line 304 -- the one that the $result is referencing.

NuPixel
12-03-2005, 11:30 AM
Problem solved. justadollarhostin Took care of it. Thanks.

hiryuu
12-04-2005, 11:41 PM
$num_auction = mysql_num_rows($result);

Code like that is a good indication that the developer has no clue what they're doing. If you just need the row count, you want COUNT(*). If you want the content, a while loop is more efficient and less error-prone than a for loop.

azizny
12-05-2005, 01:34 AM
$num_auction = mysql_num_rows($result);

Code like that is a good indication that the developer has no clue what they're doing. If you just need the row count, you want COUNT(*). If you want the content, a while loop is more efficient and less error-prone than a for loop.

depends on which context you want to use it.. I always like to use num_rows no matter what (I guess i got used to it)..

sometimes I have a $query, I then check the num, if over 1 fetch array.. if I use the count, I would have to make a new query to fetch the array..

Peace,

Burhan
12-05-2005, 02:32 AM
First thing please read the rules before you start posting threads in this forum. This forum is not to offer money for work.

Hiryuu is correct, and I'll give you a better reason to use count(*) and not mysql_num_rows. If you are trying to find out the number of rows in a very large table, you might be tempted to do SELECT id FROM `largetable` then use mysql_num_rows(). With this approach, a very large amount of data must transfer between the database server and the client. This will become an issue when (as is normally the case in "serious" applications) your database server is another physical machine connected over a network. Think of all the lag that you are introducing in your application if you do this sort of query. So in one respect, COUNT(*) is faster because it makes the database server do the heavy lifting with counting, and all you have to transfer to your client and read is one result record.

Additionally, count() provides you with a better count of what actually is in a column, in that it does take into account NULL values. Here is an example:


mysql> select * from count_test;
+----+------+
| id | foo |
+----+------+
| 1 | NULL |
| 2 | 1 |
| 3 | 2 |
| 4 | 10 |
+----+------+
4 rows in set (0.00 sec)

mysql> select count(foo) from count_test;
+------------+
| count(foo) |
+------------+
| 3 |
+------------+
1 row in set (0.00 sec)

mysql> select count(*) from count_test;
+----------+
| count(*) |
+----------+
| 4 |
+----------+
1 row in set (0.00 sec)


Note that count(*) and select * show the same number of entries

NuPixel
12-05-2005, 08:07 AM
Wow. A lot of information. Thank you WHT'ers!