Re: [PHP-DB] Help in passing multiple HTML form options to SQL query -- Newbie

2001-10-28 Thread TorrentUK

Richard,

Many thanks for that.
I was reading about the for statement in a book earlier today and wondered
if I could implement it in some way.

Looks so simple now I've been shown how :)
Thanks again.

Richard Chauvaux [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 first, the select tag in your form should be setup as an array: select
 name=country[] ... 
 then the array $country[] will be available to your script on submittal.
 a simple way to build your sql where clause would be to iterate through
 the array using a subscript variable:
 $sql = select * from tbl where ctry='$country[0]';
 for ($n=1; count($country)  $n; $n++) {
 $sql.=  or ctry='$country[$n]';
 }

 richard

 TorrentUK wrote:

  I am designing  a ski web site and am presently trying to put together a
  resort database. I started the search script tonight and am quite
pleased
  that it works. Where I am struggling is that I would like my visitors to
be
  able to select multiple countries from the drop down list and for my
query
  to pull back info on all those selected. When I try it it only pulls
back
  the last one (naturally).
 
  Please advise on what would be the most efficient way of constructing
the
  query. Please talk in easy speak as I am real new at this and am not a
  developer by any stretch of the imagination.
 
  Many Thanks
  Torrent
 
  Here is a cut down version of my code, the html form is at the bottom.
 
  ?php
 
  if ($search) {
 
   $sql = SELECT rst_name, cty_name FROM resort_tbl WHERE
  cty_name='$country';
 
   $result = mysql_query($sql);
 
   if ($row = mysql_fetch_array($result)) {
echo centertable border=1\n;
  echo trtdName/tdtdCountry/td/tr\n;
 
do {
   printf(trtd%s/tdtd%s/td\n, $row[rst_name],
  $row[cty_name]);
   } while ($myrow = mysql_fetch_array($result));
echo /table/center\n;
   }
  }
 
  ?
 
  form name=resort method=post action=?php echo $PHP_SELF?
   p Select country /fontbr
  select name=Country size=5 multiple
option value=AndorraAndorra/option
option value=AustriaAustria/option
option value=BulgariaBulgaria/option
option value=FinlandFinland/option
option value=FranceFrance/option
option value=ItalyItaly/option
option value=North AmericaNorth America/option
option value=NorwayNorway/option
option value=RomaniaRomania/option
option value=SloveniaSlovenia/option
option value=SpainSpain/option
option value=SwedenSweden/option
option value=SwitzerlandSwitzerland/option
  /select
  br
 input type=submit name=search value=Search
/p
  /form
 
 
 




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Help in passing multiple HTML form options to SQL query -- Newbie

2001-10-27 Thread TorrentUK

I am designing  a ski web site and am presently trying to put together a
resort database. I started the search script tonight and am quite pleased
that it works. Where I am struggling is that I would like my visitors to be
able to select multiple countries from the drop down list and for my query
to pull back info on all those selected. When I try it it only pulls back
the last one (naturally).

Please advise on what would be the most efficient way of constructing the
query. Please talk in easy speak as I am real new at this and am not a
developer by any stretch of the imagination.

Many Thanks
Torrent

Here is a cut down version of my code, the html form is at the bottom.

?php

if ($search) {

 $sql = SELECT rst_name, cty_name FROM resort_tbl WHERE
cty_name='$country';

 $result = mysql_query($sql);

 if ($row = mysql_fetch_array($result)) {
  echo centertable border=1\n;
echo trtdName/tdtdCountry/td/tr\n;

  do {
 printf(trtd%s/tdtd%s/td\n, $row[rst_name],
$row[cty_name]);
 } while ($myrow = mysql_fetch_array($result));
  echo /table/center\n;
 }
}

?

form name=resort method=post action=?php echo $PHP_SELF?
 p Select country /fontbr
select name=Country size=5 multiple
  option value=AndorraAndorra/option
  option value=AustriaAustria/option
  option value=BulgariaBulgaria/option
  option value=FinlandFinland/option
  option value=FranceFrance/option
  option value=ItalyItaly/option
  option value=North AmericaNorth America/option
  option value=NorwayNorway/option
  option value=RomaniaRomania/option
  option value=SloveniaSlovenia/option
  option value=SpainSpain/option
  option value=SwedenSweden/option
  option value=SwitzerlandSwitzerland/option
/select
br
   input type=submit name=search value=Search
  /p
/form



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]