For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > May 2004 > Re: [PHP-DB] question on <select>









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] question on <select>
Tony S . Wu

2004-05-12, 1:36 pm

sounds like a job for JavaScript.

Tony S. Wu
tonyswu@mac.com

"Look into the right places, you can find some good offerings."
http://homepage.mac.com/tonyswu/stw - The perfect business.
http://homepage.mac.com/tonyswu/tonyswu - My web page.
------------------------------------------------------------------------
-------



On May 12, 2004, at 7:02 AM, hengameh wrote:

>
>
> Hello,
>
> I am very new to php and mysql so please be patient with me. I don't
> even
> know if I am using the right listing, but I hope someone can help me!
>
>
>
> I need to create a <select> and the possible options are from my mysql
> database ( so far so good, I was able to find code to do that).
>
> Now I need to use the user selected option to drive the options of me
> next
> <select>. I need to know how to capture what user selected and how to
> pass
> that around? I have used "onchange" attribute of the <select> to
> capture the
> selected line but now how can I pass that to other php scripts? ( I
> need to
> get the name of the country so that I can show a list of possible
> state/province. I setting the value of the "newcountry" input to the
> selected "country" but when I do echo $newcountry in quicksearch.php,
> its
> blank!!)
>
> Please help!!
>
>
>
> Thanks so much
>
>
>
> Here is what I have so far:
>
>
>
> Quicksearch.php file has the following code
>
> <br>
>
> <table class='form'>
>
> <tr>
>
> <th>Steps 1-4</th>
>
> </tr>
>
>
>
> <tr><td>
>
> <form name="fcountry" method="post">
>
> <?php require("country_build.php");?>
>
> <input type="text" name="newcountry" value="">
>
>
>
> </form>
>
>
>
> </td></tr>
>
> </table>
>
> <!-- quicksearch.php end -->
>
>
>
> <script language="JavaScript">
>
> <!--
>
> function changeMenu()
>
> {
>
> document.fcountry.newcountry.value =
> document.fcountry.country.options[document.fcountry.country.selectedInd
> ex].v
> alue;
>
> }
>
> -->
>
> </script>
>
>
>
> Countrty_buil.php has the following
>
>
>
> <?php
>
> require_once("util.php");
>
>
>
> echo "<SELECT name=\"country\" class=\"input\"
> onchange=\"changeMenu()\">";
>
> //
>
> // initialize or capture the country variable
>
> $country = !isset($_REQUEST['country'])? "Select a country":
> $_REQUEST['country'];
>
> $countrySQL = !isset($_REQUEST['country'])? "*": $_REQUEST['country'];
>
> echo "<option value='$countrySQL' SELECTED>$country</option>";
>
> $query = "SELECT country FROM ". TABLECOUNTRY . " ORDER BY country
> ASC";
>
> // pconnect, select and query
>
> if ($link_identifier = mysql_pconnect(DBSERVERHOST, DBUSERNAME,
> DBPASSWORD))
> {
>
> if ( mysql_select_db(DBNAME, $link_identifier)) {
>
> // run the query
>
> $queryResultHandle = mysql_query($query, $link_identifier) or
> die(
> mysql_error() );
>
> $ctrRows = mysql_num_rows($queryResultHandle); // row counter
>
> // if data exists then $rows will be 1 or greater
>
> if( $ctrRows == 0 ) {
>
> echo"<option value='*'>No data
> found</option></select>";
>
> }else{
>
> // build the select list
>
> while($row = mysql_fetch_object($queryResultHandle))
> { //
> grab a row
>
> echo "<option
> value=\"$row->country\">$row->country</option>";
>
> }
>
> echo "</SELECT><br><br>";
>
>
>
> }
>
> }else{ // select
>
> echo mysql_error();
>
> }
>
> }else{ //pconnect
>
> echo mysql_error();
>
> }
>
> ?>
>
>
>
>
>
>
>
>
>


Hengameh

2004-05-12, 1:37 pm

Well I am suing Java script to capture the selected item and make it the
value of my input box. But my problem is how to access this information from
this point on. Can someone please tell me how I can use the selected item in
my next SQL query?

-----Original Message-----
From: Tony S. Wu [mailto:tonyswu@mac.com]
Sent: Wednesday, May 12, 2004 11:07 AM
To: hengameh
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] question on <select>

sounds like a job for JavaScript.

Tony S. Wu
tonyswu@mac.com

"Look into the right places, you can find some good offerings."
http://homepage.mac.com/tonyswu/stw - The perfect business.
http://homepage.mac.com/tonyswu/tonyswu - My web page.
------------------------------------------------------------------------
-------



On May 12, 2004, at 7:02 AM, hengameh wrote:

>
>
> Hello,
>
> I am very new to php and mysql so please be patient with me. I don't
> even
> know if I am using the right listing, but I hope someone can help me!
>
>
>
> I need to create a <select> and the possible options are from my mysql
> database ( so far so good, I was able to find code to do that).
>
> Now I need to use the user selected option to drive the options of me
> next
> <select>. I need to know how to capture what user selected and how to
> pass
> that around? I have used "onchange" attribute of the <select> to
> capture the
> selected line but now how can I pass that to other php scripts? ( I
> need to
> get the name of the country so that I can show a list of possible
> state/province. I setting the value of the "newcountry" input to the
> selected "country" but when I do echo $newcountry in quicksearch.php,
> its
> blank!!)
>
> Please help!!
>
>
>
> Thanks so much
>
>
>
> Here is what I have so far:
>
>
>
> Quicksearch.php file has the following code
>
> <br>
>
> <table class='form'>
>
> <tr>
>
> <th>Steps 1-4</th>
>
> </tr>
>
>
>
> <tr><td>
>
> <form name="fcountry" method="post">
>
> <?php require("country_build.php");?>
>
> <input type="text" name="newcountry" value="">
>
>
>
> </form>
>
>
>
> </td></tr>
>
> </table>
>
> <!-- quicksearch.php end -->
>
>
>
> <script language="JavaScript">
>
> <!--
>
> function changeMenu()
>
> {
>
> document.fcountry.newcountry.value =
> document.fcountry.country.options[document.fcountry.country.selectedInd
> ex].v
> alue;
>
> }
>
> -->
>
> </script>
>
>
>
> Countrty_buil.php has the following
>
>
>
> <?php
>
> require_once("util.php");
>
>
>
> echo "<SELECT name=\"country\" class=\"input\"
> onchange=\"changeMenu()\">";
>
> //
>
> // initialize or capture the country variable
>
> $country = !isset($_REQUEST['country'])? "Select a country":
> $_REQUEST['country'];
>
> $countrySQL = !isset($_REQUEST['country'])? "*": $_REQUEST['country'];
>
> echo "<option value='$countrySQL' SELECTED>$country</option>";
>
> $query = "SELECT country FROM ". TABLECOUNTRY . " ORDER BY country
> ASC";
>
> // pconnect, select and query
>
> if ($link_identifier = mysql_pconnect(DBSERVERHOST, DBUSERNAME,
> DBPASSWORD))
> {
>
> if ( mysql_select_db(DBNAME, $link_identifier)) {
>
> // run the query
>
> $queryResultHandle = mysql_query($query, $link_identifier) or
> die(
> mysql_error() );
>
> $ctrRows = mysql_num_rows($queryResultHandle); // row counter
>
> // if data exists then $rows will be 1 or greater
>
> if( $ctrRows == 0 ) {
>
> echo"<option value='*'>No data
> found</option></select>";
>
> }else{
>
> // build the select list
>
> while($row = mysql_fetch_object($queryResultHandle))
> { //
> grab a row
>
> echo "<option
> value=\"$row->country\">$row->country</option>";
>
> }
>
> echo "</SELECT><br><br>";
>
>
>
> }
>
> }else{ // select
>
> echo mysql_error();
>
> }
>
> }else{ //pconnect
>
> echo mysql_error();
>
> }
>
> ?>
>
>
>
>
>
>
>
>
>

Richard Hutchins

2004-05-12, 1:37 pm

You'd have to take the value of the first select box in your form and pass
it to another script. You can do that by setting the form's ACTION property
to either GET or POST. Personally, I prefer POST.

In the script to which you submit your form, you can access the value of the
select object thusly: $_POST["varname"] and insert it into your query
however you want (using the appropriate input sanitization methods).

The important concept to understand here is that you cannot use PHP to drive
the contents of your second select object without a round-trip to the
server. Since PHP is a server-side technology, it HAS to work that way.

To make a client-side solution possible, you'd have to send ALL POSSIBLE
data to the page all at the same time then manipulate it with JavaScript.

You can make it LOOK like a dynamic solution by repeatedly resubmitting the
page to itself and using a combo platter of JS and PHP functions on the page
to handle data as it is progressively requested/sent, but you're still doing
a round-trip each time. It only looks like a client-side solution because
you submit to the same page all the time until certain conditions are
satisfied or your user clicks on a specific link or button.

If you're truly in search of a completely client-side solution using
JavaScript, I suggest checking the Javascript Boutique or Javascript Source
or any one of the hundreds of JS repositories you'll find in a google
search. There are many great examples of this problem such as selecting a
State in one select box then having the major cities in that State show up
in a second select object.

Hope this helped.

Rich



> -----Original Message-----
> From: hengameh [mailto:haghlara@unistar-micro.com]
> Sent: Wednesday, May 12, 2004 11:34 AM
> To: 'Tony S. Wu'
> Cc: php-db@lists.php.net
> Subject: RE: [PHP-DB] question on <select>
>
>
> Well I am suing Java script to capture the selected item and
> make it the
> value of my input box. But my problem is how to access this
> information from
> this point on. Can someone please tell me how I can use the
> selected item in
> my next SQL query?
>
> -----Original Message-----
> From: Tony S. Wu [mailto:tonyswu@mac.com]
> Sent: Wednesday, May 12, 2004 11:07 AM
> To: hengameh
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] question on <select>
>
> sounds like a job for JavaScript.
>
> Tony S. Wu
> tonyswu@mac.com
>
> "Look into the right places, you can find some good offerings."
> http://homepage.mac.com/tonyswu/stw - The perfect business.
> http://homepage.mac.com/tonyswu/tonyswu - My web page.
> --------------------------------------------------------------
> ----------
> -------
>
>
>
> On May 12, 2004, at 7:02 AM, hengameh wrote:
>
> me. I don't
> can help me!
> from my mysql
> options of me
> and how to
> scripts? ( I
> quicksearch.php,
> document.fcountry.country.options[document.fcountry.country.se
> lectedInd
> $_REQUEST['country'];
> $link_identifier) or
> row counter
> mysql_fetch_object($queryResultHandle))
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Hengameh

2004-05-12, 1:37 pm

Thanks so much but I am so new to all this so need more explanation please.
I think at this point I don't mind the round trip to the server side till I
find a better way. But for now I think I have what you are suggesting but
then why my "echo" is not retuning anything :
<form name="fcountry" method="post" action="$PHP_SELF">
<?php require("country_build.php");?>
<input type="text" name="newcountry" value="">
<?php echo $_POST['newcountry'];?>
</form>
(country_build.php creates the select and its options)


-----Original Message-----
From: Hutchins, Richard [mailto:Richard.Hutchins@Getingeusa.com]
Sent: Wednesday, May 12, 2004 11:45 AM
To: php-db@lists.php.net
Subject: RE: [PHP-DB] question on <select>

You'd have to take the value of the first select box in your form and pass
it to another script. You can do that by setting the form's ACTION property
to either GET or POST. Personally, I prefer POST.

In the script to which you submit your form, you can access the value of the
select object thusly: $_POST["varname"] and insert it into your query
however you want (using the appropriate input sanitization methods).

The important concept to understand here is that you cannot use PHP to drive
the contents of your second select object without a round-trip to the
server. Since PHP is a server-side technology, it HAS to work that way.

To make a client-side solution possible, you'd have to send ALL POSSIBLE
data to the page all at the same time then manipulate it with JavaScript.

You can make it LOOK like a dynamic solution by repeatedly resubmitting the
page to itself and using a combo platter of JS and PHP functions on the page
to handle data as it is progressively requested/sent, but you're still doing
a round-trip each time. It only looks like a client-side solution because
you submit to the same page all the time until certain conditions are
satisfied or your user clicks on a specific link or button.

If you're truly in search of a completely client-side solution using
JavaScript, I suggest checking the Javascript Boutique or Javascript Source
or any one of the hundreds of JS repositories you'll find in a google
search. There are many great examples of this problem such as selecting a
State in one select box then having the major cities in that State show up
in a second select object.

Hope this helped.

Rich



> -----Original Message-----
> From: hengameh [mailto:haghlara@unistar-micro.com]
> Sent: Wednesday, May 12, 2004 11:34 AM
> To: 'Tony S. Wu'
> Cc: php-db@lists.php.net
> Subject: RE: [PHP-DB] question on <select>
>
>
> Well I am suing Java script to capture the selected item and
> make it the
> value of my input box. But my problem is how to access this
> information from
> this point on. Can someone please tell me how I can use the
> selected item in
> my next SQL query?
>
> -----Original Message-----
> From: Tony S. Wu [mailto:tonyswu@mac.com]
> Sent: Wednesday, May 12, 2004 11:07 AM
> To: hengameh
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] question on <select>
>
> sounds like a job for JavaScript.
>
> Tony S. Wu
> tonyswu@mac.com
>
> "Look into the right places, you can find some good offerings."
> http://homepage.mac.com/tonyswu/stw - The perfect business.
> http://homepage.mac.com/tonyswu/tonyswu - My web page.
> --------------------------------------------------------------
> ----------
> -------
>
>
>
> On May 12, 2004, at 7:02 AM, hengameh wrote:
>
> me. I don't
> can help me!
> from my mysql
> options of me
> and how to
> scripts? ( I
> quicksearch.php,
> document.fcountry.country.options[document.fcountry.country.se
> lectedInd
> $_REQUEST['country'];
> $link_identifier) or
> row counter
> mysql_fetch_object($queryResultHandle))
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
dpgirago@mdanderson.org

2004-05-12, 1:37 pm

> Thanks so much but I am so new to all this so need more explanation
please.
> I think at this point I don't mind the round trip to the server side

till I
> find a better way. But for now I think I have what you are suggesting

but
> then why my "echo" is not retuning anything :
> <form name="fcountry" method="post" action="$PHP_SELF">
> <?php

require("country_build.php");?>
> <input type="text"

name="newcountry" value="">
> <?php echo

$_POST['newcountry'];?>
> </form>



Well, there is no value assgined to $_POST['newcountry'] in your example.
How are you getting a value to that form field?

dave
Hengameh

2004-05-12, 1:37 pm

Here is the complete code. In the one line Java script that I have I am
setting the value. So what am I missing?

Quicksearch.php file has the following code

<br>

<table class='form'>

<tr>

<th>Steps 1-4</th>

</tr>



<tr><td>

<form name="fcountry" method="post">

<?php require("country_build.php");?>

<input type="text" name="newcountry" value="">



</form>



</td></tr>

</table>

<!-- quicksearch.php end -->



<script language="JavaScript">

<!--

function changeMenu()

{

document.fcountry.newcountry.value =
document.fcountry.country.options[document.fcountry.country.selectedIndex].v
alue;

}

-->

</script>



Countrty_buil.php has the following



<?php

require_once("util.php");



echo "<SELECT name=\"country\" class=\"input\" onchange=\"changeMenu()\">";

//

// initialize or capture the country variable

$country = !isset($_REQUEST['country'])? "Select a country":
$_REQUEST['country'];

$countrySQL = !isset($_REQUEST['country'])? "*": $_REQUEST['country'];

echo "<option value='$countrySQL' SELECTED>$country</option>";

$query = "SELECT country FROM ". TABLECOUNTRY . " ORDER BY country ASC";

// pconnect, select and query

if ($link_identifier = mysql_pconnect(DBSERVERHOST, DBUSERNAME, DBPASSWORD))
{

if ( mysql_select_db(DBNAME, $link_identifier)) {

// run the query

$queryResultHandle = mysql_query($query, $link_identifier) or die(
mysql_error() );

$ctrRows = mysql_num_rows($queryResultHandle); // row counter

// if data exists then $rows will be 1 or greater

if( $ctrRows == 0 ) {

echo"<option value='*'>No data found</option></select>";

}else{

// build the select list

while($row = mysql_fetch_object($queryResultHandle)) { //
grab a row

echo "<option
value=\"$row->country\">$row->country</option>";

}

echo "</SELECT><br><br>";



}

}else{ // select

echo mysql_error();

}

}else{ //pconnect

echo mysql_error();

}

?>




-----Original Message-----
From: dpgirago@mdanderson.org [mailto:dpgirago@mdanderson.org]
Sent: Wednesday, May 12, 2004 12:14 PM
To: php-db@lists.php.net
Subject: RE: [PHP-DB] question on <select>

> Thanks so much but I am so new to all this so need more explanation

please.
> I think at this point I don't mind the round trip to the server side

till I
> find a better way. But for now I think I have what you are suggesting

but
> then why my "echo" is not retuning anything :
> <form name="fcountry" method="post" action="$PHP_SELF">
> <?php

require("country_build.php");?>
> <input type="text"

name="newcountry" value="">
> <?php echo

$_POST['newcountry'];?>
> </form>



Well, there is no value assgined to $_POST['newcountry'] in your example.
How are you getting a value to that form field?

dave
dpgirago@mdanderson.org

2004-05-12, 1:38 pm

> Here is the complete code. In the one line Java script that I have I am
> setting the value. So what am I missing?


For the sake of the listers trying to help you, and for your own clarity
of concept, I'd suggest starting out by putting all your code into one
file. It's quite hard to follow as you've presented it.

Also, it may make it easier if you try concatenating all your output to
one $variable, then print/echoing it out.

Don't mean to be difficult, but we all have our own projects to work on.

dave
Hengameh

2004-05-12, 1:38 pm

Sorry that. I was trying to be modular! I also understand that everyone is
busy and I highly appreciate any help.
Anyway I cleaned it up a bit I hope its clear now ( all I am trying to do is
to show a list of countries from my database and then according to the
selected country make another select for the state/province and then pass
all that for further search):


<script language="JavaScript">
<!--
function changeMenu(pulldown,input)
{
input.value = pulldown.options[pulldown.selectedIndex].value;
}
-->
</script>

<?php require_once("util.php");?>

<br>
<table class='form'>
<tr><th>Steps 1-4</th></tr>
<tr><td>
<form name="fcountry" method="post" action="$PHP_SELF">
<?php getcountry();?>
<input type="text" name="newcountry" value="">
<?php echo $_POST['newcountry'];?>
</form>
</td></tr>
</table>
<!-- quicksearch.php end -->

<?php
function getcountry()
{
$sretval = "<SELECT name=\"country\" class=\"input\"
onchange=\"changeMenu(document.fcountry.country,document.fcountry.newcountry
)\">";
//
// initialize or capture the country variable
$country = !isset($_REQUEST['country'])? "Select a country":
$_REQUEST['country'];
$countrySQL = !isset($_REQUEST['country'])? "*": $_REQUEST['country'];
$sretval .= "<option value='$countrySQL' SELECTED>$country</option>";
$query = "SELECT * FROM ". TABLECOUNTRY . " ORDER BY country ASC";
// pconnect, select and query
if ($link_identifier = mysql_pconnect(DBSERVERHOST, DBUSERNAME, DBPASSWORD))
{
if ( mysql_select_db(DBNAME, $link_identifier)) {
// run the query
$queryResultHandle = mysql_query($query, $link_identifier) or
die( mysql_error() );
$ctrRows = mysql_num_rows($queryResultHandle); // row counter
// if data exists then $rows will be 1 or greater
if( $ctrRows == 0 ) {
$sretval .="<option value='*'>No data
found</option></select>";
}else{
// build the select list
while($row = mysql_fetch_object($queryResultHandle))
{ // grab a row
$sretval .="<option
value=\"$row->country\">$row->country</option>";
}
$sretval .= "</SELECT><br><br>";
echo $sretval;
}
}else{ // select
echo mysql_error();
}
}else{ //pconnect
echo mysql_error();
}
}
?>


-----Original Message-----
From: dpgirago@mdanderson.org [mailto:dpgirago@mdanderson.org]
Sent: Wednesday, May 12, 2004 12:41 PM
To: hengameh; php-db@lists.php.net
Subject: RE: [PHP-DB] question on <select>

> Here is the complete code. In the one line Java script that I have I am
> setting the value. So what am I missing?


For the sake of the listers trying to help you, and for your own clarity
of concept, I'd suggest starting out by putting all your code into one
file. It's quite hard to follow as you've presented it.

Also, it may make it easier if you try concatenating all your output to
one $variable, then print/echoing it out.

Don't mean to be difficult, but we all have our own projects to work on.

dave

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

2004-05-13, 10:30 am

Thanks everyone for all your help.
I found some code that is using Java script and although it's not fully
functional yet I am working on it. If anyone is interested here it is:

<?php require_once("util.php"); /*file holding DB info*/
global $db;
$db = mysql_connect(DBSERVERHOST, DBUSERNAME, DBPASSWORD);
if (!$db)
{
echo "Unable to connect to DB".mysql_error();
exit;
}

$selecteddb = mysql_select_db(DBNAME, $db);
if (!$selecteddb)
{
echo "Unable to select DBNAME:" .mysql_error();
exit;
}

?>
<html>
<head>
<title>.: Combobox :.</title>
<style type="text/css">
<!--
select {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 7pt;
font-style: normal;
font-weight: bold;
color: #000000;
background-color: #FFFFFF;
height: 16px;
width: 300px;
border: 1px solid #000000;
}
#left {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 7pt;
font-style: normal;
font-weight: bold;
color: #000000;
background-color: #FFFFFF;
text-align: right;
vertical-align: middle;
height: 16px;
width: 150px;
}
#right {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 7pt;
font-style: normal;
font-weight: bold;
color: #000000;
background-color: #FFFFFF;
text-align: right;
vertical-align: middle;
height: 16px;
width: 300px;
}
-->
</style>
<Script Language="JavaScript">
function getStates(what) {
if (what.selectedIndex != '') {
var country = what.value;
document.location=('combobox.php?cSel=' + country);
}
}
function getDistrict(what) {
if (what.selectedIndex != '') {
var country = document.myForm.cSelect.selectedIndex;
var state = what.value;
document.location=('combobox.php?cSel=' + country + '&sSel=' +
state);
}
}
function getCity(what) {
if (what.selectedIndex != '') {
var state = document.myForm.sSelect.selectedIndex;
var district = what.value;
document.location=('combobox.php?cSel=' + country + '&sSel=' + state
+ '&dSel=' + district);
}
}
</script>
</head>

<body>
<form name="myForm" method="post" action="">
<table width="450" align="center" cellpadding="1" cellspacing="1">
<tr>
<td id="left">Select your Country:</td>
<td id="right">
<select name="cSelect" onChange="getStates(this);">
<option value="">please, select your country</option>
<?php
global $db;
// Country Select Box Populated with Values from 'country' table.
$country_qu = mysql_query("SELECT * FROM country ORDER BY country", $db);
while ($country_array = mysql_fetch_array($country_qu)) {
$cNa = $country_array["country"];
$cAb = $country_array["cabbrev"];

// This keeps the COuntry elected after JScript has Refreshed the page.

if ($cSel == $cNa) {
echo "<option value=$cNa Selected>$cNa</option>";
} else {
echo "<option value=$cNa>$cNa</option>";
}

}
?>
</select>
</td>
</tr>
<tr>
<td id="left">Select your State or Province:</td>
<td id="right">
<select name="sSelect" onChange="getDistrict(this);">
<option value="">please, select your state or province</option>
<?php
global $db;
// State Select Box Populated with Values from 'stateprovince' table.
if ($cSel) {
$state_qu = mysql_query("SELECT * FROM stateprovince WHERE
country='$cSel' ORDER BY stateprovince",$db);
if (!$state_qu)
{
echo "Could not successfully run the query" .mysql_error();
exit;
}
$sNum = mysql_num_rows($state_qu);
// I put this IF STATEMENT here incase you ever have citys that are not
in states. Just Countrys.
if ($sNum == "0") {
$ctNoState = "none";
} else {
while ($state_array = mysql_fetch_array($state_qu)) {
$sNa = $state_array["stateprovince"];
$sId = $state_array["pid"];
$sCu = $state_array["country"];

// This keeps the state selected after JScript has Refreshed
the page.
if ($sSel == $sId) {
echo "<option value=$sId Selected>$sNa, $sCu</option>";
} else {
echo "<option value=$sId>$sNa, $sCu</option>";
}

}
}
}
?>
</td>
</tr>

<tr>
<td id="left">Select your District:
</td>

<td id="right">
<select name="dSelect" onChange="getCity(this);">
<option value="">please, select your district</option>

<?php
// District Select Box Populated with Values from 'district' table.

if ($sSel) {
// This is the SQL you should keep if you're gonna delete the IF, ELSE
IF.
$district_sql = "SELECT did,pid,district FROM district WHERE pid='$sSel'
ORDER BY district";
}

if ($district_sql != "") {
$district_qu = mysql_query($district_sql,$db);
while ($district_array = mysql_fetch_array($district_qu)) {
$dNa = $district_array["district"];
$dId = $district_array["did"];
$dPid = $district_array["pid"];
echo "<option value=$dId>$dNa</option>";
}
}
?>
</select>
</td>
</tr>


<tr>
<td id="left">Select your City:
</td>

<td id="right">
<select name="ctSelect">
<option value="">please, select your city</option>

<?php
// City Select Box Populated with Values from 'city' table.

// If and ELSE IF are if you have citys inside countrys (no states) Just
Delete it if its not needed.
if ($dSel) {
// This is the SQL you should keep if you're gonna delete the IF, ELSE
IF.
$city_sql = "SELECT city,cityid, did FROM city WHERE did=$dSel ORDER BY
city";
}
//else if ($cSel && ($ctNoState == "none")) {
// $city_sql = "SELECT city,cityid, did FROM city WHERE countryid=$cSel
ORDER BY city_name";
//}
if ($city_sql != "") {
$city_qu = mysql_query($city_sql);
while ($city_array = mysql_fetch_array($city_qu)) {
$ctNa = $city_array["city"];
$ctId = $city_array["cityid"];
echo "<option value=$ctId>$ctNa</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td id="left"></td>
<td id="right"></td>
</tr>
</table>
</form>
</body>
</html>

-----Original Message-----
From: Neil Smith [MVP, Digital media] [mailto:php@comatose.freeserve.co.uk]
Sent: Thursday, May 13, 2004 4:16 AM
To: php-db-digest-help@lists.php.net
Cc: haghlara@unistar-micro.com
Subject: Re:RE: [PHP-DB] question on <select>

That *should* read :

document.fcountry.newcountry.value =
document.fcountry.country[document.fcountry.country.selectedIndex].value;

Skip the 'options' object - I'm surprised you're not getting a javascript
error, maybe you have error reporting turned off in your browser ? In any
case, always 'alert' that value when you create it, so you know what you're
actually submitting during testing.

At 04:06 13/05/2004 +0000, you wrote:
>From: "hengameh" <haghlara@unistar-micro.com>
>To: <dpgirago@mdanderson.org>,
> <php-db@lists.php.net>
>Date: Wed, 12 May 2004 12:22:20 -0400
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="us-ascii"
>Content-Transfer-Encoding: 7bit
>Message-ID: <SERVERHfqR77bieLYCT00000048@mail.unistar-micro.com>
>Subject: RE: [PHP-DB] question on <select>
>
><!--
>function changeMenu()
> {
> document.fcountry.newcountry.value =
>document.fcountry.country.options[document.fcountry.country.selectedIndex].

v
>alue;
> }
>-->
></script>



========================================
================
CaptionKit http://www.captionkit.com : Production tools
for accessible subtitled internet media, transcripts
and searchable video. Supports Real Player, Quicktime
and Windows Media Player.

VideoChat with friends online, get Freshly Toasted every
day at http://www.fresh-toast.net : NetMeeting solutions
for a connected world.
Neil Smith [Mvp

2004-05-13, 2:31 pm

That *should* read :

document.fcountry.newcountry.value =
document.fcountry.country[document.fcountry.country.selectedIndex].value;

Skip the 'options' object - I'm surprised you're not getting a javascript
error, maybe you have error reporting turned off in your browser ? In any
case, always 'alert' that value when you create it, so you know what you're
actually submitting during testing.

At 04:06 13/05/2004 +0000, you wrote:
>From: "hengameh" <haghlara@unistar-micro.com>
>To: <dpgirago@mdanderson.org>,
> <php-db@lists.php.net>
>Date: Wed, 12 May 2004 12:22:20 -0400
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="us-ascii"
>Content-Transfer-Encoding: 7bit
>Message-ID: <SERVERHfqR77bieLYCT00000048@mail.unistar-micro.com>
>Subject: RE: [PHP-DB] question on <select>
>
><!--
>function changeMenu()
> {
> document.fcountry.newcountry.value =
>document.fcountry.country.options[document.fcountry.country.selectedIndex].v
>alue;
> }
>-->
></script>




========================================
================
CaptionKit http://www.captionkit.com : Production tools
for accessible subtitled internet media, transcripts
and searchable video. Supports Real Player, Quicktime
and Windows Media Player.

VideoChat with friends online, get Freshly Toasted every
day at http://www.fresh-toast.net : NetMeeting solutions
for a connected world.
Michael Forbes

2004-05-13, 5:30 pm

Interesting idea. Since I'm convinced that javascript is the bastard
offspring of Bill Gates, Larry Ellison, and Baalzebub, can I sue too? :)


Hengameh wrote:
[color=darkred]
> Well I am suing Java script to capture the selected item and make it the
> value of my input box. But my problem is how to access this information from
> this point on. Can someone please tell me how I can use the selected item in
> my next SQL query?
>
> -----Original Message-----
> From: Tony S. Wu [mailto:tonyswu@mac.com]
> Sent: Wednesday, May 12, 2004 11:07 AM
> To: hengameh
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] question on <select>
>
> sounds like a job for JavaScript.
>
> Tony S. Wu
> tonyswu@mac.com
>
> "Look into the right places, you can find some good offerings."
> http://homepage.mac.com/tonyswu/stw - The perfect business.
> http://homepage.mac.com/tonyswu/tonyswu - My web page.
> ------------------------------------------------------------------------
> -------
>
>
>
> On May 12, 2004, at 7:02 AM, hengameh wrote:
>
>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com