Re: get one name for each row

2002-05-02 Thread Pradeep Dsouza

Try this

Table : col1 : col2
1.  Hotel 1

select name = my_selection
?php
include config.php;
$res = mysql_query(SELECT * FROM tname);

while ($row = mysql_fetch_array($res))
{
$col1 = $row[col1];
$col2 = $row[col2];
option value = \$col1\  $col2

}
   /select

?
Pradeep

Naharonline.com


- Original Message -
From: savaidis [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, May 02, 2002 1:37 PM
Subject: get one name for each row



 I have one table with about 1000 hotels and name or the city they belong.
 I want to run a query to get one row for every city only, to put it in a
 pull down menu in the search form.
 How is that?

 Makis



 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail
[EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: get one name for each row

2002-05-02 Thread Victoria Reznichenko

savaidis,
Thursday, May 02, 2002, 11:07:18 AM, you wrote:

s I have one table with about 1000 hotels and name or the city they belong.
s I want to run a query to get one row for every city only, to put it in a
s pull down menu in the search form.
s How is that?

Try SELECT DISTINCT city FROM your_table;

s Makis




-- 
For technical support contracts, goto https://order.mysql.com/
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___ ___   __
  /  |/  /_ __/ __/ __ \/ /Victoria Reznichenko
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
   ___/   www.mysql.com




-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: get one name for each row

2002-05-02 Thread Jay Blanchard

[snip]
I have one table with about 1000 hotels and name or the city they belong.
I want to run a query to get one row for every city only, to put it in a
pull down menu in the search form.
How is that?
[/snip]

SELECT DISTINCT city
FROM tblFOO

So if you have this table;

+---++
| City  |  Hotel|
+---++
| Houston| Hotel A  |
| Houston| Hotel B  |
| Houston| Hotel C  |
| San Antonio  | Hotel A  |
| Dallas   | Hotel A  |
| Detroit   | Hotel A  |
| Detroit   | Hotel B  |
+---++

The query will return;

+---+
| City  | 
+---+
| Houston|
| San Antonio  |
| Dallas   |
| Detroit   |
+---+

Hope this helps!

Jay Blanchard


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: get one name for each row

2002-05-02 Thread Issvar

It might be faster to instead of getting the list of cities and then in
seperate queries get all hotels for each city, to just sort by city and
fetch all, and in your application check if it has found a next city
already.

Example in php:
$res=mysql_query('select hotel,city from hotels order by city');
$lastcity=;
$firstline=;
while (list($hotel,$city)=mysql_fetch_row($res)) {
  if ($city!=$lastcity) {
$lastcity=$city;
echo brb$city/b;
  }
  echo $hotel ;
}

Just an example, change the html output to what you want it.

- Original Message -
From: savaidis [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, May 02, 2002 10:07 AM
Subject: get one name for each row



 I have one table with about 1000 hotels and name or the city they belong.
 I want to run a query to get one row for every city only, to put it in a
 pull down menu in the search form.
 How is that?

 Makis



 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail [EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: get one name for each row

2002-05-02 Thread Jay Blanchard

[snip]
It might be faster to instead of getting the list of cities and then in
seperate queries get all hotels for each city, to just sort by city and
fetch all, and in your application check if it has found a next city
already.
[/snip]

Of course, you could use a single crosstab query and get something like

CITY1   Hotel1  Hotel2  Hotel3  Hotel4
CITY2   Hotel1  Hotel2
CITY3   Hotel1  Hotel2  Hotel3
CITY4   Hotel1  Hotel2  Hotel3  Hotel4  Hotel5

Jay Blanchard


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: get one name for each row

2002-05-02 Thread savaidis

I tried
select distinct Location from hotels1 order by Location
and worked.
But how can I show all fields of the rows?
It doesn't accept any field before distinct and shows every row after
distinct (if I put select distinct Location, Name ... )


Thanks again

Makis


 -Original Message-
 From: Jay Blanchard [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, May 02, 2002 3:23 PM
 To: 'savaidis'; [EMAIL PROTECTED]
 Subject: RE: get one name for each row


 [snip]
 I have one table with about 1000 hotels and name or the city they belong.
 I want to run a query to get one row for every city only, to put it in a
 pull down menu in the search form.
 How is that?
 [/snip]

 SELECT DISTINCT city
 FROM tblFOO

 So if you have this table;

 +---++
 | City  |  Hotel|
 +---++
 | Houston| Hotel A  |
 | Houston| Hotel B  |
 | Houston| Hotel C  |
 | San Antonio  | Hotel A  |
 | Dallas   | Hotel A  |
 | Detroit   | Hotel A  |
 | Detroit   | Hotel B  |
 +---++

 The query will return;

 +---+
 | City  |
 +---+
 | Houston|
 | San Antonio  |
 | Dallas   |
 | Detroit   |
 +---+

 Hope this helps!

 Jay Blanchard



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: get one name for each row

2002-05-02 Thread Jay Blanchard

[snip from mysql list message]
I tried
select distinct Location from hotels1 order by Location
and worked.
But how can I show all fields of the rows?
It doesn't accept any field before distinct and shows every row after
distinct (if I put select distinct Location, Name ... )
[/snip]

Can we see your table? Can you also write out what you expect the results to
be?

Thanks!

Jay Blanchard



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: get one name for each row

2002-05-02 Thread savaidis

The table has about 80 fields.
I would something like:
select *, distinct Location from hotels order by Name (this one creates a
MySQL error)
to one full row for every Location.
I suppose I have to do it with a php script.
(with limit 1 to the second query)

You can see it at http://www.macedonia-hotels.gr


Makis


 -Original Message-
 From: Jay Blanchard [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, May 02, 2002 6:59 PM
 To: 'savaidis'; [EMAIL PROTECTED]
 Subject: RE: get one name for each row


 [snip from mysql list message]
 I tried
 select distinct Location from hotels1 order by Location
 and worked.
 But how can I show all fields of the rows?
 It doesn't accept any field before distinct and shows every row after
 distinct (if I put select distinct Location, Name ... )
 [/snip]

 Can we see your table? Can you also write out what you expect the
 results to
 be?

 Thanks!

 Jay Blanchard



 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail [EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php