Jump to content

drop down


Kathy

Recommended Posts

I'm veryvery used to PHP, but am wondering if it would be better to do this in Javascript? I'm trying to populate a drop down with a database table called categories and a field called Category, after selecting a category from this drop down, I'd like it to select another drop down from a table called clients and a field called CoName, after picking a company I'd like the company's contact details to be displayed in a way? Any suggestions?

Link to comment
Share on other sites

Rather than either/or, you will want to use both. You need to do it in php, because some users will not have javascript enabled, and you cut them off if you don't have a php fallback. But adding this functionality in javascript makes for a nicer user experience. So I recommend building it in php, then adding the javascript after the fact. (This is called unobtrusive javascripting by the way).

Link to comment
Share on other sites

Okay, I've done the following:

<?
// Connect database

$link = mysql_connect("host","login","pass");
mysql_select_db("dbname", $link);

$query = "select Category FROM categories"; 
$results = mysql_query($query, $link) or die("Error performing query"); 

if(mysql_num_rows($results) > 0){ 

		echo("<select name=\"Category\">"); 
while($row = mysql_fetch_object($results)){ 
echo("<option value=\"$row->record_id\">$row->Category</option>"); 
} 
echo("</select>"); 
} 


	?>

I would now like to be able to populate another drop down based on the selection of the above drop down from a table called clients and a field name called coName, I'd appreciate ANY help, thanks!

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.