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>';
}

Link to comment
Share on other sites

$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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.