473,480 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiple 'similar' dropdowns -> 1 query

Hi there

I'm building this CMS, and at a point i have
3 similar drop downs. The values of the drop
downs are called from a MysqlDB.

The first one is just fine:
do{

$selected = ($_GET['id_1'] == $result['id']) ? ' selected' : '';

echo '<option'.$selected.'>'.$result['id'].'</option>';

}while($result = mysql_fetch_array($query));
If the value of $_GET['id_1'] matches a value from the DB,
that value is selected in the final dropdown.

But when i try to do it again with $_GET[id_2] or $_GET[id_3], it
fails.
How can i 'recall' the mysql info?

Thanks.

Frizzle.

Jul 27 '05 #1
6 1422
I noticed that Message-ID:
<11*********************@g49g2000cwa.googlegroups. com> from frizzle
contained the following:
But when i try to do it again with $_GET[id_2] or $_GET[id_3], it
fails.
How can i 'recall' the mysql info?


I usually create an array of the db info then create the from that. All
you need to do then is check if $_GET[id_n] is in the array.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 27 '05 #2
Hmm, could you maybe explain a little bit more?
I'm not trying to find a better way for the '$selected'-part,
but i'm not able (yet) to create the same dropdown three
times from 1 query ...

Thanks.

Frizzle.

Jul 27 '05 #3
I noticed that Message-ID:
<11**********************@g43g2000cwa.googlegroups .com> from frizzle
contained the following:
Hmm, could you maybe explain a little bit more?
I'm not trying to find a better way for the '$selected'-part,
but i'm not able (yet) to create the same dropdown three
times from 1 query ...


If you are doing something more than once you need to be thinking
'function'
Let is say you query the database and do a loop to put the values in an
array. In the following function, $name is the name of the select box,
$array is the array from the database and $sel is the selection you are
testing.

function mk_select($name,$array,$sel){
$string = "<select name=\"$name\"class=\"input\">";
foreach ($array AS $key=>$value) {
if($key==$sel){$selected=" selected";}
else{$selected="";}
$string .= "<option
value=\"$key\"$selected>$value</option>\n";
}
$string.="</select>";
return $string;
}
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 27 '05 #4
Hmm, being the newbie i am, i still can't get it to work:
i have $result = mysql_fetch_array($get_result);

Works fine with a

do{
foo
}while($result = mysql_fetch_array($get_result));

It returns the following from the DB:

id code
____________
27 ABC becomes: <option value="27">ABC</option>
35 KNO becomes: <option value="35">KNO</option>
57 TRE etc.
81 FLO etc.
____________

But when i call your function like this:
echo mk_select('name_1', $result, 'find_this');
it returns 4 items wich is correct, but the first two
are one id, and the third and fourth are a code.

Something like this:
id code
____________
<option value="">27</option>
<option value="">27</option>
<option value="">KNO</option>
<option value="">KNO</option>
____________

i just can't figure it out ...

Greetings Frizzle.

Jul 27 '05 #5
I noticed that Message-ID:
<11*********************@g43g2000cwa.googlegroups. com> from frizzle
contained the following:
Hmm, being the newbie i am, i still can't get it to work:
i have $result = mysql_fetch_array($get_result);

Works fine with a

do{
foo
}while($result = mysql_fetch_array($get_result));

It returns the following from the DB:

id code
____________
27 ABC becomes: <option value="27">ABC</option>
35 KNO becomes: <option value="35">KNO</option>
57 TRE etc.
81 FLO etc.
____________

So $result[id] ==27 $result[code]==ABC

You have to combine those into a new array
$select_array=array();
while($result = mysql_fetch_array($get_result)){
$select_array[$result[id]]=$result[code];
}

Then your new array will contain the database rows as key/value pairs
and you can use it in the function.

echo mk_select('name_1', $select_array, 'find_this');
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 27 '05 #6
Great!
As you've probably read, i didn't put the query in an array first.
Now everything works fine!
Thanks a lot!

Frizzle.

Jul 29 '05 #7

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

Similar topics

2
1911
by: Crescionini Sascha | last post by:
Hello NG If I let appear a DIV over a HTML site with dropdowns, this dropdowns are still visible. Is there a way to push them to the back? All other form elements arent visible. greets...
11
4612
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
2
2892
by: Greg | last post by:
Hi all, Is there a way to copy multiple objects into the clipboard and then paste them? What I want to achive is to be able to copy UI controls (textedits, dropdowns, etc) from one form and...
3
1563
by: Damon | last post by:
I am working on a site in which I would like to have two dropdowns that will allow a user to navigate through the administrative pages of the site. The first would allow the user to choose the...
1
1454
by: Andy | last post by:
What I want to do is to populate multiple dropdowns when editing. Presumably... a) I should use a DataReader so that I can get each ResultSet for each dropdown control, and that should cut down...
2
1036
by: bingomanatee | last post by:
I have developed what amounts to a fancy shopping cart wizard for a scientific instrument using VB.NET. We are having some disturbing phenomena relating to dropdown controls. On my system and...
3
1206
by: Simon Harvey | last post by:
Hi everyone, I keep getting a problem with dropdownlist controls. It sounds really stupid, but my app is screwed as long as this keeps happening. It seems to spontaneously happen and then I...
7
1380
by: chhatra | last post by:
I have 8 dropdowns to be filled from database . To avoid roundtrips to the database what i should use?
0
1599
by: bogorman | last post by:
Am trying to add a "video" to a webpage which is based on a template containing a javascript menu. The site has hundreds of pages all based on this template and the menu works fine The page can be...
0
951
by: sbart | last post by:
I am programing in asp.net vb using AjaxToolkit cascadingDropDown. I do not have access to AjaxToolkit cascading dropdown event handlers. I have a series of dropdowns. The selection from one of...
0
7051
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
7054
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
7097
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...
1
6750
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...
1
4794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.