RE: question on <select>

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

 



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@xxxxxxxxxxxxxx [mailto:dpgirago@xxxxxxxxxxxxxx] 
Sent: Wednesday, May 12, 2004 12:41 PM
To: hengameh; php-db@xxxxxxxxxxxxx
Subject: RE:  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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux