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
https://forums.phpfreaks.com/topic/165783-drop-down/
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
https://forums.phpfreaks.com/topic/165783-drop-down/#findComment-874509
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
https://forums.phpfreaks.com/topic/165783-drop-down/#findComment-875031
Share on other sites

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.