|
Posted by Jerry Stuckle on 12/02/07 02:03
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
==================
Navigation:
[Reply to this message]
|