473,405 Members | 2,379 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,405 software developers and data experts.

Pull Down Menu Query

I'm trying to populate the pulldown menus of a single input form
through queries from a single table. The three columns are 'name',
'type', and 'status'. The name table runs to approx row 23, the type,
to row 8, and status, row 9. . I'm using the following code to
populate the form pulldown menus::

<?php
$query = "SELECT DISTINCT status
FROM $table";
$result = mysql_query($query);
$number = mysql_numrows($result);

for ($i=0; $i<$number; $i++) {
$status = mysql_result($result,$i,"status");
print "<option value=\"$status\">$status</option>";
}

mysql_close();
?>
The interesting portion here is that 'name' only allows a single blank
space on the pulldown as I had expected and so does 'status'. 'Type'
on the other hand, shows 2 blank spaces on the pulldown menu so what's
with that? Is there some sort of 'end of file marker' that I should
be inserting to the database columns to get this to read correctly?
TIA
Jul 26 '07 #1
5 1707
On 26.07.2007 09:51 Toby A Inkster wrote:
cover wrote:
>$query = "SELECT DISTINCT status
FROM $table";

Most databases optimise GROUP BY better than DISTINCT. Generally speaking,
if you can avoid DISTINCT, you should: it forces the database engine to
retrieve rows and then discard them, whereas often, especially with
well-indexed columns, the engine will be able to do smarter things with
GROUP BY.
Don't know about "most" ones, mysql docs explicitly says they're equivalent

http://dev.mysql.com/doc/refman/5.0/...imization.html
--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Jul 26 '07 #2
gosha bine wrote:
Don't know about "most" ones, mysql docs explicitly says they're equivalent
http://dev.mysql.com/doc/refman/5.0/...imization.html
It says that SELECT DISTINCT and GROUP BY *usually* end up generating the
same execution plan, so there won't be a performance difference.

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

Cryptography Challenge
http://tobyinkster.co.uk/blog/2007/0...pto-challenge/
Jul 27 '07 #3
On 27.07.2007 11:46 Toby A Inkster wrote:
gosha bine wrote:
>Don't know about "most" ones, mysql docs explicitly says they're equivalent
http://dev.mysql.com/doc/refman/5.0/...imization.html

It says that SELECT DISTINCT and GROUP BY *usually* end up generating the
same execution plan, so there won't be a performance difference.
Pretending that you cannot read is probably the worst defense you could
come up with. ;)

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Jul 27 '07 #4
On 27 Jul, 11:31, gosha bine <stereof...@gmail.comwrote:
On 27.07.2007 11:46 Toby A Inkster wrote:
gosha bine wrote:
Don't know about "most" ones, mysql docs explicitly says they're equivalent
http://dev.mysql.com/doc/refman/5.0/...imization.html
It says that SELECT DISTINCT and GROUP BY *usually* end up generating the
same execution plan, so there won't be a performance difference.

Pretending that you cannot read is probably the worst defense you could
come up with. ;)

--
gosha bine

makrell ~http://www.tagarga.com/blok/makrell
php done right ;)http://code.google.com/p/pihipi
But it is you who cannot read!

The manual does NOT (neither explicitly not implicitly) say that GROUP
BY and DISTINCT are equivalent.

What it does say is:

"In most cases, a DISTINCT clause can be considered as a special case
of GROUP BY."

And it then says:

"For example, the following two queries are equivalent: ..."

The phrase "In most cases" implies that they are not equivalent. If
they were it would say "In all cases".

Jul 27 '07 #5
On Thu, 26 Jul 2007 08:51:22 +0100, Toby A Inkster
<us**********@tobyinkster.co.ukwrote:

<snip>

Hey, looks like some great ideas and I'll give them a try. Thank you
very much. :-)

Jul 27 '07 #6

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

Similar topics

1
by: Phillip Russell | last post by:
Is there a way for PHP to see what is selected in a pull-down menu. So that i can use a switch statement to display certain information. If not how can I combine javascript with it to work.
5
by: Glenn Mulno | last post by:
Hi, I am trying to create a report page for several teams. Each team runs the same reports but the reports use different values. For a while this was getting insane everytime I updated the...
7
by: jt | last post by:
I am new to Javascript and I am having problems with loading a pull down menu. I get this error: javax.servlet.ServletException: No data found It will list the items just fine if I just list...
1
by: NEUE | last post by:
Hello, I'm trying to have a layer appear on top of a simple pull-down menu, but in IE6 the pull-down menu always appears on top. Even if I put the pull-down in a layer under the other layers, it...
5
by: judiphuongtu | last post by:
I am trying to create an input form with a pull-down menu that allows a user to add an item to the pull-down. I don't want the page to refresh when I refresh the pull-down since there's entries on...
2
by: Keith Burns | last post by:
Hi, I have seen two entries in the archives for this topic: 1. Uses hypertext, not a pulldown menu to feed parameters back to the python CGI 2. The other actually used Java. Is there a way...
1
by: dkimbrell | last post by:
Hi there, I'm very novice to web design. I'm trying to make a pulldown menu, but the formatting keeps getting screwed up when you roll the mouse over it. Please see www.boundarysys.com for...
21
by: giandeo | last post by:
Hello Experts. Is it possible to retrieve the value from a populated pull down menu from a database and then use that value to access the same database to get the related fields. Example: ...
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...

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.