This is a discussion on Two different drop downs from mySQL within the PHP Language forums, part of the PHP Programming Forums category; Hi there, I have a admin area for a website, and on some part the admin can select options from ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi there,
I have a admin area for a website, and on some part the admin can select options from two different drop down boxes. Now i thought that it would be better to use one Query for both dropdowns. How can i get them together? I now have something similair twice: <select name="series_id" class="dropdownbox" id="series_id"> <option value="0">- select -</option> <?php $db = mysql_connect("localhost", "name", "pass"); mysql_select_db("db_name"); $result = mysql_query("SELECT * FROM series ORDER BY name"); if ($data = mysql_fetch_array($result)){ do { $current_id = $data['series_id']; if($current_id == $id){$selected = "selected";}; echo "<option value=\"".$data['series_id']."\" ".$selected.">".ucfirst($data['name'])."</option>\n"; } while ($data = mysql_fetch_array($result)); } else { echo ""; }; mysql_close($db);?> </select> I hope it's clear what i mean. I do not make connection twice, but the rest is similair except for the tablename of course. Thanks in advance.. Greetings knoakske |
|
|||
|
On 21 Jan 2005 03:32:55 -0800, knoakske@hotmail.com (knoak) wrote:
>I have a admin area for a website, and on some part the admin can >select options from two different drop down boxes. Now i thought that >it would be better to use one Query for both dropdowns. How can i get >them together? >I now have something similair twice: > ><select name="series_id" class="dropdownbox" id="series_id"> > <option value="0">- select -</option> > > <?php > $db = mysql_connect("localhost", "name", "pass"); > mysql_select_db("db_name"); > $result = mysql_query("SELECT * FROM series ORDER BY name"); > > if ($data = mysql_fetch_array($result)){ > do { > $current_id = $data['series_id']; > if($current_id == $id){$selected = "selected";}; > echo "<option value=\"".$data['series_id']."\" > ".$selected.">".ucfirst($data['name'])."</option>\n"; > } while ($data = mysql_fetch_array($result)); > } else { > echo ""; > }; > mysql_close($db);?> ></select> > >I hope it's clear what i mean. I do not make connection twice, but the >rest is similair except for the tablename of course. If it's a different table, it's a different query, so just run two queries. You should probably factor out the other code into a function though, so you're not repeating that - i.e. make it take parameters such as the SQL query (or an array of the data produced from the query), and the column names used for the data. -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |