RE: [PHP-DB] Re: arrays, variables, and register_globals

From: Date: Fri, 26 Jul 2002 05:40:55 +0000
Subject: RE: [PHP-DB] Re: arrays, variables, and register_globals
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-109678@lists.php.net to get a copy of this message
On 25 Jul 2002 at 2:04, GOLD, MATTHEW wrote: > thank you very much for your quick response. > > How do I run mysql_fetch_row before the while loop? I don't want two > loops, because I just want this variable to print out once. > > I tried this, but it didn't work: > > $query = "Select blah1, blah2, blah3 from blahtable"; > $result = mysql_query ($query) > or die ("Cannot complete query"); > > $row = mysql_fetch_row ($result)) > print ("$row[4]"); > > while ($row = mysql_fetch_row ($result)) > { > print "$row[1], $row[2], etc."); > } > > ?> > > I realize that my problem is that I don't really understand arrays...but I > am new to all of this, and I very much appreciate your help. > > best, > > Matt Not sure if I responded to this, so .... $query = "Select blah1, blah2, blah3 from blahtable"; $result = mysql_query ($query) or die ("Error: ". $mysql_error() ) //mysql_error gives you a useful error message! // or die ("Cannot complete query"); $row = mysql_fetch_row ($result)) print ("$row[4]"); mysql_data_seek($result, 0); //Reset pointer to first record while ($row = mysql_fetch_row ($result)) { print "$row[1], $row[2], etc."); } ?> You might want to look at extract as well. Cheers -- David Robley Temporary Kiwi! Quod subigo farinam "This is mutiny!" said Tom bountifully.

« previous php.general (#109678) next »