473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Jul 17 '05 #1
1 1762
On 21 Jan 2005 03:32:55 -0800, kn******@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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Martial Spirit | last post by:
Hello- I was amazed at the suckerfish drop-downs from AListApart.com. They work great except for one thing, if I position the drop-downs over an iframe element, on mouseover the menus disappear....
8
by: Kim14 | last post by:
Help! I am trying to create a webpage and it would be obvious to anyone who reads my source code (it's a mess) that I created it using a template. I know almost nothing about webpages, but am...
1
by: Joe Dunleavy | last post by:
Hi Guys, Hopefully some one will have come across this issue already. I have a DataGrid inside a Div where a scroll bar displays once a certain height is meet --> <div id="dvSales"...
3
by: CSharpguy | last post by:
I have 3 drop downs that are populated from the databasem 4 of my web pages need to have this drop down, how can I trap the selection made in the drop down and popuate my grid on my form?
1
by: ninja | last post by:
Hi I am new to PHP and I have a little problem I have created a user registration form and on this form I have three drop downs one for title, prov/state and country. This creates a record in the...
2
by: John | last post by:
I have CSS drop down navigatoon bar and it works fine. However, when I have page where I have an <embed - needed to show a PDF file, such as: <embed src="Security.pdf" width="900"...
0
by: ehsanen | last post by:
I have some text boxes and drop downs on my web page and now i want to put a button in my webpage that when the user clicked the buton the page itself add another row of textboxes and drop downs , in...
1
by: JackInDaBox | last post by:
Hello, I am new to this and have run into a small problem. I am using the Ajax toolkit with VS 2005 to fill some drop downs through a web service and it works great. All of the cascading drop...
4
by: phub11 | last post by:
Hi, I've found a great website which can extract data from a MySQL database and populate chained drop downs. (http://www.noboxmedia.com/20/massive-ajax-countryarea-drop-down-list/) I'd like the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.