Reply to Re: problem with mysql_num_rows()

Your name:

Reply:


Posted by Shelly on 11/30/07 23:09

lamib wrote:
> mantrid wrote:
>> I am getting the following error. I cant see what is wrong. I am
>> probably overlooking something obvious, can anyone see what is wrong
>> ? The sql is ok as used elsewhere. Problem only occurs when i
>> include the mysql_num_rows() function
>>
>>
>> Warning: mysql_num_rows(): supplied argument is not a valid MySQL
>> result resource in /home/iddsoftw/public_html/cgtcalc/addcomp.php on
>> line 76 $sql30daycheck = "SELECT * FROM cgttransactions WHERE
>> companyid=$impcompanyid AND selldatetime IS NOT NULL AND bbprice IS
>> NULL AND selldatetime >=DATE_SUB('".$impdatetime."', INTERVAL 30
>> DAY) ORDER BY selldatetime DESC "; //LIMIT 1 DATE(NOW()) > finstart
>> AND DATE(NOW()) < DATE_ADD(finstart, INTERVAL 1 YEAR)"
>>
>> **************************
>> if(mysql_num_rows(mysql_query($sql30daycheck))){ <<<<<<<<
>> line 76
>> $q30daycheck = mysql_query($sql30daycheck);
>> while($r30daycheck =& mysql_fetch_array($q30daycheck)) {
>> extract($r30daycheck);
>>
>> ******* some code here using $r30daycheck ******
>> }
>> }
>>
>> ******************
>>
>>
>>
>>
>>
>>
>>
>
> I'm not entirely sure (as I use a MySQL library to ease the task), but
> try doing something like "$queryresult = mysql_query($sql30daycheck)"
> first and doing mysql_num_rows($queryresult).

I was going to make the same suggestion.

This reminded me of what I call the C programmer's "Name That Tune" complex.

I can code that in 5 lines.
I can do it in 4 lines.
It would only take me 3 lines .
-- Write that code!

(For those not old enough, there was a show called Name That Tune and
contestents bid on how few notes they would need to name the tune). That
kind of C programmer would put everything into the for loop so that
everything was on one line. It was a debugging -- and code reading --
nightmare. I always found it better to use 2,3,4 or 5 lines or whatever it
took so that I could put breakpoints in and readily trace what was going on
to debug a problem.

I would also have written his query as:

$sql30daycheck = "SELECT * FROM cgttransactions WHERE ".
"companyid=" . $impcompanyid . " AND ".
"selldatetime IS NOT NULL AND " . "
"bbprice IS NULL AND " .
"selldatetime >=DATE_SUB('" . $impdatetime.
"', INTERVAL 30 DAY) " .
"ORDER BY selldatetime DESC ";
` //LIMIT 1 DATE(NOW()) > finstart
//AND DATE(NOW()) <
DATE_ADD(finstart, INTERVAL 1 YEAR)

.....at least that is how the query SEEMS to be,

--
Shelly

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация