Kathy Posted July 13, 2009 Share Posted July 13, 2009 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? Quote Link to comment Share on other sites More sharing options...
haku Posted July 13, 2009 Share Posted July 13, 2009 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). Quote Link to comment Share on other sites More sharing options...
Kathy Posted July 14, 2009 Author Share Posted July 14, 2009 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! Quote Link to comment Share on other sites More sharing options...
napsternapster Posted July 14, 2009 Share Posted July 14, 2009 you need to $_get[value] made and then use that value to search information you need in your database. Quote Link to comment Share on other sites More sharing options...
haku Posted July 14, 2009 Share Posted July 14, 2009 I agree, though I generally prefer $_POST values over $_GET values, as it's a little harder for someone to play with the values. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.