Two different drop downs from mySQL

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-21-2005
knoak
 
Posts: n/a
Default Two different drop downs from mySQL

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
Reply With Quote
  #2 (permalink)  
Old 01-22-2005
Andy Hassall
 
Posts: n/a
Default Re: Two different drop downs from mySQL

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0