RE: [PHP-DB] Select statement only returns 1 record
| From: | Todd Williamsen | Date: | Wed, 30 Jan 2002 20:17:38 +0000 |
| Subject: | RE: [PHP-DB] Select statement only returns 1 record | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-16330@lists.php.net to get a copy of this message | ||
Nope, that doesn't work
-----Original Message-----
From: Rick Emery [mailto:remery@excel.com]
Sent: Wednesday, January 30, 2002 1:01 PM
To: 'Todd Williamsen'; php-db@lists.php.net
Subject: RE: [PHP-DB] Select statement only returns 1 record
<?
$db = mysql_connect($dbserver, $dbuser, $dbpass);
mysql_select_db($dbname,$db);
$sortby = "name ASC";
$sql="SELECT * FROM webl_players ORDER BY $sortby";
$result=mysql_query($sql,$db);
print "<select name="canidate">";
while( $row = mysql_fetch_array($result) )
{
$FirstName = $row['FirstName'];
$LastName = $row['LastName'];
$id=$row['id'];
print "<option value=$id >$LastName, $FirstName</option>";
}
?>
print "</SELECT>";
-----Original Message-----
From: Todd Williamsen [mailto:todd@williamsen.net]
Sent: Wednesday, January 30, 2002 12:45 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Select statement only returns 1 record
I am trying to get data from two columns, FirstName and Last name and
displaying all the records LastName, FirstName in a drop down menu.
The weird thing is that it only displays one record. I thought the
table
was hosed, but its not. I tried it through another database and still
doesn't work.
Here is the code:
<?
$db = mysql_connect($dbserver, $dbuser, $dbpass);
mysql_select_db($dbname,$db);
$sortby = "name ASC";
$sql="SELECT * FROM webl_players ORDER BY $sortby";
$result=mysql_query($sql,$db);
$row = mysql_fetch_array($result);
$FirstName = $row["FirstName"];
$LastName = $row["LastName"];
?>
<select name="canidate">
<option selected>
<?php echo "$LastName, $FirstName"; ?>
</option>
I would list the whole page but its long! There is another SQL
statement at
the top of the page:
<?php
$db = mysql_connect($dbserver, $dbuser, $$dbpass);
mysql_select_db($dbname, $db);
$sql = "SELECT * FROM Canidate SORT BY 'LastName'";
$result = mysql_query($sql);
?>
--
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