This is a discussion on problem with mysql_num_rows() within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am getting the following error. I cant see what is wrong. I am probably overlooking something obvious, can anyone ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 ****** } } ****************** |
|
|||
|
Ok
Im an idiot. It was the sql, but not because the syntax was wrong. It was just that the sql was using variables taken from rows of a text file. while (($data = fgetcsv($handle, 1500)) !== FALSE) { list($imptype,$impuserid, $impmyvarid,$impcompanyid, $impaimlisted, $impamount, $impprice, $impstamp, $impcomm, $impdate,$imptime) = $data; // explode(",", $data) ...... ...... ..etc } and i recently modified the structure of the text file without making appropriate changes in the php. tut tut Thank for your interest Ian "mantrid" <ian.dandav@virgin.net> wrote in message news:Wj04j.74$1j1.72@newsfe7-gui.ntli.net... > 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 ****** > } > } > > ****************** > > > > > > > |
|
|||
|
mantrid wrote:
> Ok > Im an idiot. It was the sql, but not because the syntax was wrong. It was > just that the sql was using variables taken from rows of a text file. > > while (($data = fgetcsv($handle, 1500)) !== FALSE) { > list($imptype,$impuserid, $impmyvarid,$impcompanyid, $impaimlisted, > $impamount, $impprice, $impstamp, $impcomm, $impdate,$imptime) = $data; // > explode(",", $data) > ..... > ..... > .etc > } > > and i recently modified the structure of the text file without making > appropriate changes in the php. tut tut > > Thank for your interest > Ian > > > > "mantrid" <ian.dandav@virgin.net> wrote in message > news:Wj04j.74$1j1.72@newsfe7-gui.ntli.net... >> 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 ****** >> } >> } >> >> ****************** >> >> >> >> >> >> >> > > > But the other comments are still valid. Right now you're calling mysql_query() twice; the second call is completely unnecessary and causes additional overhead on MySQL and your script. Rather, do this: $q30daycheck = mysql_query($sql30daycheck); if (mysql_num_rows($q309daycheck)) { while($r30daycheck =& mysql_fetch_array($q30daycheck)) { extract($r30daycheck); .... And please - RENAME YOUR VARIABLES. Having two 12 character variables which differ only by the first character is confusing and encourages errors in your code. For instance - use $result for the request from the query. Much easier to understand. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message news:i8WdnTCdEvI2Wc3anZ2dnUVZ_ommnZ2d@comcast.com. .. > mantrid wrote: > > Ok > > Im an idiot. It was the sql, but not because the syntax was wrong. It was > > just that the sql was using variables taken from rows of a text file. > > > > while (($data = fgetcsv($handle, 1500)) !== FALSE) { > > list($imptype,$impuserid, $impmyvarid,$impcompanyid, $impaimlisted, > > $impamount, $impprice, $impstamp, $impcomm, $impdate,$imptime) = $data; // > > explode(",", $data) > > ..... > > ..... > > .etc > > } > > > > and i recently modified the structure of the text file without making > > appropriate changes in the php. tut tut > > > > Thank for your interest > > Ian > > > > > > > > "mantrid" <ian.dandav@virgin.net> wrote in message > > news:Wj04j.74$1j1.72@newsfe7-gui.ntli.net... > >> 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 ****** > >> } > >> } > >> > >> ****************** > >> > >> > >> > >> > >> > >> > >> > > > > > > > > But the other comments are still valid. > > Right now you're calling mysql_query() twice; the second call is > completely unnecessary and causes additional overhead on MySQL and your > script. > > Rather, do this: > > $q30daycheck = mysql_query($sql30daycheck); > if (mysql_num_rows($q309daycheck)) { > while($r30daycheck =& mysql_fetch_array($q30daycheck)) { > extract($r30daycheck); > ... > > And please - RENAME YOUR VARIABLES. Having two 12 character variables > which differ only by the first character is confusing and encourages > errors in your code. > > For instance - use $result for the request from the query. Much easier > to understand. > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstucklex@attglobal.net > ================== > "Right now you're calling mysql_query() twice; the second call is completely unnecessary and causes additional overhead on MySQL and your script." Your are correct. I always do it your way, honestly. I posted the code I had just been playing around with trying different things to see if I could get it working. Hence the messiness of it with all the commented out code etc. > And please - RENAME YOUR VARIABLES. Having two 12 character variables > which differ only by the first character is confusing and encourages > errors in your code. You are right again. This is a habit of mine. I do it so i can identify different calls to the database on the same page. I could use $result1, $result2 etc. but this makes it easier for me. Also the small difference is always at the front and follows the same pattern $sqlsomething for the sql statement, $qsomething for the mysql_query, $rsomething for the mysql_fetch etc. It makes sense for me and im not in a team so dont have the problem of others needing to read my code |
|
|||
|
On the subject of variable length. Does a variable with a long name effect
performance? "mantrid" <ian.dandav@virgin.net> wrote in message news:Q5j4j.1674$jy3.1207@newsfe7-win.ntli.net... > > > "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message > news:i8WdnTCdEvI2Wc3anZ2dnUVZ_ommnZ2d@comcast.com. .. > > mantrid wrote: > > > Ok > > > Im an idiot. It was the sql, but not because the syntax was wrong. It > was > > > just that the sql was using variables taken from rows of a text file. > > > > > > while (($data = fgetcsv($handle, 1500)) !== FALSE) { > > > list($imptype,$impuserid, $impmyvarid,$impcompanyid, $impaimlisted, > > > $impamount, $impprice, $impstamp, $impcomm, $impdate,$imptime) = $data; > // > > > explode(",", $data) > > > ..... > > > ..... > > > .etc > > > } > > > > > > and i recently modified the structure of the text file without making > > > appropriate changes in the php. tut tut > > > > > > Thank for your interest > > > Ian > > > > > > > > > > > > "mantrid" <ian.dandav@virgin.net> wrote in message > > > news:Wj04j.74$1j1.72@newsfe7-gui.ntli.net... > > >> 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 ****** > > >> } > > >> } > > >> > > >> ****************** > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > > > > > > > > > > > > But the other comments are still valid. > > > > Right now you're calling mysql_query() twice; the second call is > > completely unnecessary and causes additional overhead on MySQL and your > > script. > > > > Rather, do this: > > > > $q30daycheck = mysql_query($sql30daycheck); > > if (mysql_num_rows($q309daycheck)) { > > while($r30daycheck =& mysql_fetch_array($q30daycheck)) { > > extract($r30daycheck); > > ... > > > > And please - RENAME YOUR VARIABLES. Having two 12 character variables > > which differ only by the first character is confusing and encourages > > errors in your code. > > > > For instance - use $result for the request from the query. Much easier > > to understand. > > > > -- > > ================== > > Remove the "x" from my email address > > Jerry Stuckle > > JDS Computer Training Corp. > > jstucklex@attglobal.net > > ================== > > > > > "Right now you're calling mysql_query() twice; the second call is > completely unnecessary and causes additional overhead on MySQL and your > script." > > Your are correct. I always do it your way, honestly. I posted the code I had > just been playing around with trying different things to see if I could get > it working. Hence the messiness of it with all the commented out code etc. > > > And please - RENAME YOUR VARIABLES. Having two 12 character variables > > which differ only by the first character is confusing and encourages > > errors in your code. > > You are right again. This is a habit of mine. I do it so i can identify > different calls to the database on the same page. I could use $result1, > $result2 etc. but this makes it easier for me. Also the small difference is > always at the front and follows the same pattern > $sqlsomething for the sql statement, $qsomething for the mysql_query, > $rsomething for the mysql_fetch etc. It makes sense for me and im not in a > team so dont have the problem of others needing to read my code > > |
|
|||
|
mantrid wrote:
> On the subject of variable length. Does a variable with a long name effect > performance? > Not so as you would notice. (and nowhere near as much as two calls to mysql-num-rows). BTW. Not trimming properly when you reply to posts will upset a lot of people. Regards (another) Ian |
|
|||
|
mantrid wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message >> But the other comments are still valid. >> >> Right now you're calling mysql_query() twice; the second call is >> completely unnecessary and causes additional overhead on MySQL and your >> script. >> >> Rather, do this: >> >> $q30daycheck = mysql_query($sql30daycheck); >> if (mysql_num_rows($q309daycheck)) { >> while($r30daycheck =& mysql_fetch_array($q30daycheck)) { >> extract($r30daycheck); >> ... >> >> And please - RENAME YOUR VARIABLES. Having two 12 character variables >> which differ only by the first character is confusing and encourages >> errors in your code. >> >> For instance - use $result for the request from the query. Much easier >> to understand. >> > > > "Right now you're calling mysql_query() twice; the second call is > completely unnecessary and causes additional overhead on MySQL and your > script." > > Your are correct. I always do it your way, honestly. I posted the code I had > just been playing around with trying different things to see if I could get > it working. Hence the messiness of it with all the commented out code etc. > OK, no problem. I just mentioned it because I wasn't sure if you were aware of it or not. Not knowing how much PHP experience you have, this type of error is common amongst beginners. >> And please - RENAME YOUR VARIABLES. Having two 12 character variables >> which differ only by the first character is confusing and encourages >> errors in your code. > > You are right again. This is a habit of mine. I do it so i can identify > different calls to the database on the same page. I could use $result1, > $result2 etc. but this makes it easier for me. Also the small difference is > always at the front and follows the same pattern > $sqlsomething for the sql statement, $qsomething for the mysql_query, > $rsomething for the mysql_fetch etc. It makes sense for me and im not in a > team so dont have the problem of others needing to read my code > > I know, I started out in Fortran II about 40 years ago when variables were limited to 6 (I think) characters. And even after learning other languages I kept that idea for a long time. But Hungarian Notation (which is what you're using) has fallen out of favor in the past few years, especially with untyped languages such as PHP. But what I was referring to was not so much $sqlsomething or $rsomething (although I do like $result, $queryNameResult or similar. I meant the use of $k, $_k especially. You shouldn't start a variable name with an underscore (it's generally reserved for system stuff), and it's very difficult to see what you're doing in your loops with such similar names. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Greetings, mantrid.
In reply to Your message dated Saturday, December 1, 2007, 04:06:08, > Im an idiot. It was the sql, but not because the syntax was wrong. It was > just that the sql was using variables taken from rows of a text file. Why it is always true to have valid SQL resultset before coding something in other languages. If You getting an error around mysql_query, first make sure You have expected result in it. Then check something other. -- Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru> |
|
|||
|
Greetings, Jerry Stuckle.
In reply to Your message dated Sunday, December 2, 2007, 05:03:10, > But what I was referring to was not so much $sqlsomething or $rsomething > (although I do like $result, $queryNameResult or similar. I meant the > use of $k, $_k especially. You shouldn't start a variable name with an > underscore (it's generally reserved for system stuff), and it's very > difficult to see what you're doing in your loops with such similar names. While You partially true, I'd point to the fact that __names reserved for system use. Im using $_name variables to identify read-only temporary storages such as query strings ($_q typically) and resultsets ($_r, $_rc or something), which is used almost immediately and assigned only once. Larger code part where I use such names was completely fit to screen and easy to observe. While I know that such short names are not allowed due to lack of meaning, I have this behaviour properly documented in project description. And it is really easy to code short names while You have mass of dealing with external I/O (either database, files or remote websites). Another use of _names is an internal object properties and methods, where it is easier to determine if that property/method is public or private/protected. -- Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru> |
|
|||
|
AnrDaemon wrote:
> Greetings, Jerry Stuckle. > In reply to Your message dated Sunday, December 2, 2007, 05:03:10, > >> But what I was referring to was not so much $sqlsomething or $rsomething >> (although I do like $result, $queryNameResult or similar. I meant the >> use of $k, $_k especially. You shouldn't start a variable name with an >> underscore (it's generally reserved for system stuff), and it's very >> difficult to see what you're doing in your loops with such similar names. > > While You partially true, I'd point to the fact that __names reserved for > system use. > Right now I don't see where either one is not recommended, but I know I've seen it someplace. Just have to find out where. > Im using $_name variables to identify read-only temporary storages such as > query strings ($_q typically) and resultsets ($_r, $_rc or something), which > is used almost immediately and assigned only once. Larger code part where I > use such names was completely fit to screen and easy to observe. > If it's a constant, then it should be defined as a constant. Such naming conventions make your code much harder for anyone else to understand. > While I know that such short names are not allowed due to lack of meaning, I > have this behaviour properly documented in project description. > It still doesn't mean the names aren't confusing. It's much better to use meaningful names. And if something is a constant, it should be defined as a constant. > And it is really easy to code short names while You have mass of dealing with > external I/O (either database, files or remote websites). > And it's really easy to make your code virtually unreadable by someone else when using short names. > Another use of _names is an internal object properties and methods, where it > is easier to determine if that property/method is public or private/protected. > > Keep all your properties private, as they should be, and you don't have the problem. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
![]() |
| Thread Tools | |
| Display Modes | |
|
|