|
Posted by mantrid on 12/01/07 20:08
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
>
>
Navigation:
[Reply to this message]
|