For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > May 2004 > 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 question on <select>
Hengameh

2004-05-12, 10:35 am



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.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();

}

?>










Neil Smith [Mvp

2004-05-13, 4:31 am

** Or send XML files up and down dynamically using xmlhttp in IE and
Mozilla ;-)

Cheers - Neil

At 04:06 13/05/2004 +0000, you wrote:
>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.

Sponsored Links







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

Copyright 2008 codecomments.com