RE: Populating an array from mysql db

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28 August 2003 17:25, mike karthauser wrote:

> on 28/8/03 5:00 pm, CPT John W. Holmes at
> holmes072000@charter.net wrote:
> 
> > > Thanks for this - I ended up rehashing my query to this:
> > > 
> > > <?
> > > $result = mysql_query("SELECT * FROM dates WHERE bookcode =
> > > '$bookcode' ORDER BY date1",$db); 
> > > 
> > > 
> > > // loop to populate array
> > > 
> > > $myrow = mysql_fetch_array($result);
> > > 
> > > $i = 1;
> > > while ($i <= '30') {
> > > 
> > > if ($myrow['date'.$i] > '0000-00-00')
> > 
> > You're making PHP do some extra work here. You're testing to see if
> > one string is greater than another... how can strings be greater
> > than or less than? Why don't you just check for $myrow['date'.$i]
> > != '0000-00-00' ?? 
> 
> Thanks. I'll make your change.

While you're about it, remove the quotes from

    while ($i <= '30') {

as well -- saves a conversion from string to integer each time round the loop (well, unless PHP optimises it out of the loop, but why take the chance?!).

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux