problem with mysql_num_rows()
problem with mysql_num_rows()
am 30.11.2007 23:40:54 von mantrid
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 ******
}
}
******************
Re: problem with mysql_num_rows()
am 30.11.2007 23:55:26 von lamib
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).
--
www.lamib.info
Re: problem with mysql_num_rows()
am 01.12.2007 00:09:36 von Shelly
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
Re: problem with mysql_num_rows()
am 01.12.2007 02:06:08 von mantrid
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" 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 ******
> }
> }
>
> ******************
>
>
>
>
>
>
>
Re: problem with mysql_num_rows()
am 01.12.2007 03:05:34 von luiheidsgoeroe
On Sat, 01 Dec 2007 00:09:36 +0100, Shelly =
wrote:
>> I'm not entirely sure (as I use a MySQL library to ease the task), bu=
t
>> try doing something like "$queryresult =3D 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). T=
hat
> 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 whatev=
er =
> it
> took so that I could put breakpoints in and readily trace what was goi=
ng =
> on
> to debug a problem.
Indeed, when efficiency of several possible solutions to a problem are =
close, please, pleasego for the most legible one. Number of lines are no=
t =
a way to determine efficiency.
> I would also have written his query as:
>
> $sql30daycheck =3D "SELECT * FROM cgttransactions WHERE ".
> "companyid=3D" . $impcompanyid . " AN=
D ".
> "selldatetime IS NOT NULL AND " . "
> "bbprice IS NULL AND " .
> "selldatetime >=3DDATE_SUB('" . =
> $impdatetime.
> "', INTERVAL 30 DAY) " .
I would never do that. A query is one string, _with_ possible linebreaks=
, =
and MySQL (if thats the flavour of your choice, which it usually is) wil=
l =
tell you on which line the error was if there was any. Quite a handy =
feature I'd say.
Can someone please explain this nonsense about not wanting linebreaks in=
=
strings when they're perfectly legal (and in this case quite handy), and=
=
concatinating further on other lines? HTML disregards whitespace like th=
at =
(save a few issues with UA's, in which case you just open/close the tags=
=
on another line). I know it's the default of the IMHO unsuited for PHP u=
se =
Eclipse, which is one editor which has so many problems with my deault =
coding style (and is quite bloated Java). It really was the final turn-o=
ff =
for me (there are many, many other reasons) not to use that one. Yes, I =
=
know I can change it in the settings.
Then again, I'm posting this 'cooling down' after a night out, so please=
=
disregard any spelling errors and wrong assumptions.
-- =
Rik Wasmus
Re: problem with mysql_num_rows()
am 01.12.2007 03:19:01 von Jerry Stuckle
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" 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
==================
Re: problem with mysql_num_rows()
am 01.12.2007 21:02:56 von mantrid
"Jerry Stuckle" 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" 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
Re: problem with mysql_num_rows()
am 01.12.2007 21:08:34 von mantrid
On the subject of variable length. Does a variable with a long name effect
performance?
"mantrid" wrote in message
news:Q5j4j.1674$jy3.1207@newsfe7-win.ntli.net...
>
>
> "Jerry Stuckle" 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" 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
>
>
Re: problem with mysql_num_rows()
am 02.12.2007 00:08:50 von Ian Hobson
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
Re: problem with mysql_num_rows()
am 02.12.2007 03:03:10 von Jerry Stuckle
mantrid wrote:
> "Jerry Stuckle" 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
==================
Re: problem with mysql_num_rows()
am 03.12.2007 13:09:40 von AnrDaemon
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
Re: problem with mysql_num_rows()
am 03.12.2007 13:21:25 von AnrDaemon
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
Re: problem with mysql_num_rows()
am 03.12.2007 14:15:35 von Jerry Stuckle
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
==================