RE: Looking for help with forms/variables and an array!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I thank you kindly for your pointers.
It did really help me with getting further.
Persons like yourself are truly talented to be able and bang out the theory
like that on the fly.

Only problem is that I am using php to learn code for the first real time.
The Microsoft stuff started to throw me off.

I am going sit hear and study your example intently and hopefully it will
clue me off on my major variable error.

I am right there with it!

Brad

-----Original Message-----
From: Dan Shirah [mailto:mrsquash2@xxxxxxxxx] 
Sent: Tuesday, June 12, 2007 3:05 PM
To: Jim Lucas
Cc: BSumrall; php-general@xxxxxxxxxxxxx
Subject: Re:  Looking for help with forms/variables and an array!

Wouldn't a little javascript solve this problem??

Have your first dropdown menu, then when an option is selected use a
javascript Onchange function to refresh (post) the page to itself.   This
would set the selected option as your "form1" value.  Then just write a
simple query using that value to return the options you want for dropdown
#2.

Something like this:

<select name="states" onchange="this.submit();">
<option value="AL" > Alabama
<option value="FL" >Florida
<option value="WA" >Washington
<option value="MI" >Michigan
</select>

if (!isset($_POST['submit'])) {
  $state = $_POST['states'];

Then put your result in an array and populate your second dropdown.

<td width="43" align="right">City:</td>
<td width="135" align="left" class="tblcell_sm">
<SELECT name="city">
<?php
  $database = mssql_select_db("database", $connection) or die ('DB selection
failed');
  // Query the table and load all of the records into an array.
  $q_cities = "SELECT * FROM cities WHERE state_name = '$state'";
  $r_cities = mssql_query($q_cities) or die(mssql_error());
  while ($rec_cities = mssql_fetch_assoc($r_cities)) $c_city[] =
$rec_cities;

  echo "<OPTION value=\"\">--SELECT--</OPTION>\n";
  foreach ($c_city as $s_city)
  {
    if ($s_city['state_name'] == $_POST['states'])
      echo "<OPTION value=\"{$s_city['city_code']}\"
SELECTED>{$s_city['city_name']}</OPTION>\n";
    else
      echo "<OPTION
value=\"{$s_city['city_code']}\">{$s_cc['city_name']}</OPTION>\n";
  }
?>
</SELECT>
</td>

Hope that helps??  lol

On 6/12/07, Jim Lucas <lists@xxxxxxxxx> wrote:
>
> BSumrall wrote:
> > It doesn't like the curly brackets either!
> >
> > Brad
> >
>
> if this is within PHP, the '{' and '}' are within double quotes (which
> they seem to be),
>
> These examples should all do the same thing.
>
> $query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range =
> '$select1'";
> $query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range =
> '{$select1}'";
> $query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range =
> '".$select1."'";
>
> echo $query_Recordset1;
>
> place an echo just after including the variable and see if you see the
> brackets in the statement.
>
>
> --
> Jim Lucas
>
>    "Some men are born to greatness, some achieve greatness,
>        and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
>     by William Shakespeare
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux