Jump to content

how to display only one column of results...


jasonc

Recommended Posts

I have a table of data and wish to only display the `name` column on the page.

 

I have tried a few methods looking at php.net site but just can not seem to get this right and show only the `name` column, there are about 10 names so far but only the first of each name is showing in the selection pull down menu?

 

$res = db_query("SELECT `name` FROM `client_names` WHERE `customer_id` = '". $customer_id ."'");
$res_array = mysql_fetch_row($res);
//$maincount = mysql_num_rows($res);
foreach ($res_array as $res2) {
$form_text .= '<option value="'.$res2['name'].'"' . $selected . '>'.$res2['name'].'</option>';
}

$query = "SELECT `name` FROM `client_names` WHERE `customer_id` = $customer_id"; // assuming $customer_id is an integer
$query = mysql_query( $query ); // can add or die( mysql_error() ) if necessary for debugging query execution
while( $array = mysql_fetch_assoc($result) ) { // returns an associative array
     echo $array['name'] . '<br />'; // echo each array element while the condition is true
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.