473,490 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

drop down populated by database

Hello, hopefully someone can help me with this: I currently have a php
file that pulls a query from the field "category" from my database.
this file is called category.php. I am trying to populate a drop down
box in another page (called add_subpage.php) from the results of the
category page. the code below is on the add_subpage.php file: (It was
my best guess and does not work)

<select name="category">
<option value="CAT"<?php include 'category.php' ?>></option</select>

Can anyone tell me how to make this drop down populate from the
category php file?

I really appreciate any help!! Thank you

God bless
jason

Jun 7 '07 #1
4 2206
Message-ID: <11**********************@p47g2000hsd.googlegroups .comfrom
jsd219 contained the following:
><select name="category">
<option value="CAT"<?php include 'category.php' ?>></option</select>

Can anyone tell me how to make this drop down populate from the
category php file?
We need to see category.php.

If this file produces an array (called say $categories) then you could
do something like this:

<select name="category">
foreach ($categories as $category){
echo "<option >$category</option>\n";
}
?>
</select>
--
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/
Jun 7 '07 #2
On Jun 7, 1:11 pm, Geoff Berrow <blthe...@ckdog.co.ukwrote:
Message-ID: <11**********************@p47g2000hsd.googlegroups .comfrom
jsd219 contained the following:
<select name="category">
<option value="CAT"<?php include 'category.php' ?>></option</select>
Can anyone tell me how to make this drop down populate from the
category php file?

We need to see category.php.

If this file produces an array (called say $categories) then you could
do something like this:

<select name="category">
foreach ($categories as $category){
echo "<option >$category</option>\n";}

?>
</select>
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDshttp://www.ckdog.co.uk/rfdmaker/
Thank you, i have one more question now. :-) i need to see the results
from my table where column Category has anything in it. I am assuming
i would use a WHERE statement but i don't know how to tell it to look
for anything in the field.

God bless
jason

Jun 7 '07 #3
Message-ID: <11**********************@q69g2000hsb.googlegroups .comfrom
jsd219 contained the following:
>Thank you, i have one more question now. :-) i need to see the results
from my table where column Category has anything in it. I am assuming
i would use a WHERE statement but i don't know how to tell it to look
for anything in the field.
Something like this:

$categories=array();
$sql="SELECT DISTINCT category FROM table WHERE category!=''";
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
$categories[]=$row['category'];
}

--
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/
Jun 7 '07 #4
Geoff Berrow wrote:
$sql="SELECT DISTINCT category FROM table WHERE category!=''";
Although tempting to use, SELECT DISTINCT is normally a sign of a place
where things could be done better.

SELECT MIN(category) FROM table WHERE category!='' GROUP BY category;

will achieve the same effect, but on most databases will run slightly
faster. This is because SELECT DISTINCT effectively fetches rows and then
discards them, whereas GROUP BY only fetches the needed rows to begin with.

If you don't believe me, try using the "EXPLAIN" feature on your database
to see which is faster.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 104 days, 18:07.]

URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
Jun 8 '07 #5

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

Similar topics

3
11227
by: julian | last post by:
hi I was wondering if anyone can help me out on this.... I have dynamcally populated a drop down menu with data from an access database using ASP. The values seem fine, however when i pass...
46
5096
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
4
6281
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
2
9441
by: kmnotes04 | last post by:
Is it possible to link one drop-down box to another? For example, if a name is chosen from a drop-down list, can another drop-down list then automatically display the person's office as a result of...
2
1489
by: SirPoonga | last post by:
Lets say I have a couple of tables in a database containg car make, type, and model. I want to create a drop down box that is populated by the makes. Based on that selection run a query to get...
2
4548
by: Ren | last post by:
Hi all, I am a bit new to PHP and SQL so this may seem like a dumb question. I have already created a drop down list as part of a form which is automatically populated with values taken from a...
1
2082
by: accyboy1981 | last post by:
Hi, I new to C# so please forgive me if this is simple. I've got 2 drop down lists the first is hard coded with data where as the second is populated from a database. The options that appear in...
7
2422
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit...
2
2840
by: millertime90 | last post by:
Hi basically my problem is I have 2 drop down menus populated by my database the first populated by a field in the database and the 2nd populated with a relation to the value selected in the first...
1
1087
by: JohnMV | last post by:
Hi, I have 3 related drop down menus all of which need to be populated from database.In the first list i populated the values from the database. But i have trouble to proceed further. The...
0
7112
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
7146
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,...
1
6852
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
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
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
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1389
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 ...
0
277
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.