Link to home
Start Free TrialLog in
Avatar of tjyoung
tjyoung

asked on

Trouble populating a selectlist with values from a single record

Hi,
I'm not sure if its obvious but I'm struggling with below. I'm querying the db to populate the select list looking to get both phone numbers from  a single record. My resulting selectlist only contains just one phone number instead of the leadPhone and leadOtherPhone for that record.

What am I missing and I'll go bang my head on a wall when its pointed out:
<select name="dialnumber" id="dialnumber">
<?php
$query = "SELECT leadPhone, leadOtherPhone FROM leads WHERE user_id = '$current_id' AND id = '$thelead'";
$result = mysql_query($query) or die(mysql_error());
		echo("<option value=\"\">Choose a Number</option>");
		while($row = mysql_fetch_row($result)) {
		echo("<option value=\"$row[0]\">$row[0]</option>");
		}
?>

Open in new window


So if the record contained a number in each column... I'm only getting the first one populating my selectlist.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It may make your code easier to read if you fetch an object rather than a row. You can then refer to the columns by name...

$row = mysql_fetch_object($result);
printf("<option value='%s'>%s</option>", $row->leadPhone, $row->leadPhone );
printf("<option value='%s'>%s</option>", $row->leadOtherPhone, $row->leadOtherPhone );

Open in new window

FYI - The mysql library is deprecated so sooner rather than later you should be switching to either the PDO or mySQLi libraries.

Ray Paseur, an Expert here on EE, has written a great article about it:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
Avatar of tjyoung
tjyoung

ASKER

Shoot me... it would be a mercy killing.
Thanks for the swat upside the head Chris.
:)

We all need it from time to time...