Jump to content

multiple entries appearing


newbie_07

Recommended Posts

Hello to all.

i am new to php.

 

I have the following code:

 

$sql = "SELECT client_info.client_id, client_info.f_name, client_info.l_name, services.service_name 
	From client_info, services";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)){
$c_id = $row['client_id'];
//$s_name = $row['service_name'];
$s_names .="<option>$row[service_name]</option>";
$c_names .="<option value=$c_id>".$row['f_name']." ".$row['l_name']."</option>";
}

 

I am displaying client_names and services names in a listbox.

All are coming but they are appearing multiple times. I don't know why?

Please help

 

Link to comment
Share on other sites

Your sql did not include the joining statement...

 

Try these:

SELECT client_info.client_id, client_info.f_name, client_info.l_name, services.service_name FROM client_info, services WHERE client_info.service_id = services.service_id

 

I am just make a guess that your client_info had a field named service_id(foreign key) which linked to the services table with a same primary key field name.

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.