RE: [PHP-DB] MySQL Query Weirdness
easier solution: while ($line = mysql_fetch_array($result)) { print \ttr\n\t\ttd.$line['first_name'].\n\t/tr\n; } -Original Message- From: Steve Cayford [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 20, 2001 5:16 PM To: Chris S. Cc: [EMAIL PROTECTED] 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 \ttr\n; while(list($col_name, $col_value) = each($line)) { print \t\ttd$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. [EMAIL PROTECTED] PGP 0xDA39672B -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] MySQL Query Weirdness
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 \ttr\n; while(list($col_name, $col_value) = each($line)) { print \t\ttd$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. [EMAIL PROTECTED] PGP 0xDA39672B -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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 \ttr\n; while(list($col_name, $col_value) = each($line)) { print \t\ttd$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. [EMAIL PROTECTED] PGP 0xDA39672B -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]