RE: [PHP-DB] MySQL Query Weirdness

From: Date: Fri, 21 Sep 2001 12:20:25 +0000
Subject: RE: [PHP-DB] MySQL Query Weirdness
Groups: php.db 
Request: Send a blank email to php-db+get-12635@lists.php.net to get a copy of this message
easier solution: while ($line = mysql_fetch_array($result)) { print "\t<tr>\n\t\t<td>".$line['first_name']."\n\t</tr>\n"; } -----Original Message----- From: Steve Cayford [mailto:steve_cayford@unioncab.com] Sent: Thursday, September 20, 2001 5:16 PM To: Chris S. Cc: php-db@lists.php.net Subject: Re: [PHP-DB] MySQL Query Weirdness When you use mysql_fetch_array you're actually retrieving an array with two copies of the value you're looking for. One is indexed by the column number and one indexed by the column name. So it looks like you're looping through them both and printing each out. You might want mysql_fetch_assoc (to use just the column name) or mysql_fetch_row (to use just the column number) -Steve On Thursday, September 20, 2001, at 05:02 PM, Chris S. wrote: > > > Hello, > > I'm new at this php/mysql stuff, so go easy on my guys. > > I've got my query script up and working, but the problem is I'm getting > the > same column printed twice on the html output. Here is the output: > > Connected successfully > Chris Chris > Mark Mark > Mike Mike > Dee Dee > etc... > > Here is my .php script: > > <?php > $link = mysql_connect("localhost", "dbuser","dbpassword") > or die ("Could not connect"); > print ("Connected successfully"); > mysql_select_db ("dapscores") or die ("Could not select database"); > > $query = "SELECT first_name FROM overall_results"; > $result = mysql_query ($query) or die ("Query failed"); > > // printing HTML result > > print "<table>\n"; > while ($line = mysql_fetch_array($result)) { > print "\t<tr>\n"; > while(list($col_name, $col_value) = each($line)) { > print "\t\t<td>$col_value</td>\n"; > } > print "\t</tr>\n"; > } > > print "</table>\n"; > > > > mysql_close($link); > ?> > > > Here is my database layout: > > mysql> describe overall_results; > +---------------+-------------+------+-----+---------+-------+ > | Field | Type | Null | Key | Default | Extra | > +---------------+-------------+------+-----+---------+-------+ > | Match_Date | date | YES | | NULL | | > | Place | varchar(10) | YES | | NULL | | > | Last_Name | varchar(20) | YES | | NULL | | > | First_Name | varchar(20) | YES | | NULL | | > | USPSA | varchar(10) | YES | | NULL | | > | Class | char(3) | YES | | NULL | | > | Division | varchar(20) | YES | | NULL | | > | PF | varchar(7) | YES | | NULL | | > | Lady | char(3) | YES | | NULL | | > | Mil | varchar(4) | YES | | NULL | | > | Law | varchar(4) | YES | | NULL | | > | F0r | char(3) | YES | | NULL | | > | Age | varchar(20) | YES | | NULL | | > | Match_Pts | float | YES | | NULL | | > | Match_percent | float | YES | | NULL | | > +---------------+-------------+------+-----+---------+-------+ > > If I run the query from mysql>, it works fine, just the HTML output > shows > the double column thing. Is this a database problem? I've tried > different > variations of my script and I get the same output each time. > > Thanks > > -- > Chris S. > chris@c62023-a.wntck1.sfba.home.com > PGP 0xDA39672B > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#12635) next »