ebanbury 13 Junior Poster

Hi
I currently have a form in which you select from the prop_type field and then a field with the relevant subtypes shows up.

The saletypes are currently in 5 separate fields right now (saletype1 -5), all showing records from the same mysql table, using a different recordset each. They are hidden at the start and then a different field appears depending on selection.

What I would like to be able to do is to have my initial prop_type field as it is now, but the saletype field showing underneath as one field only and then depending on what is selected first, the data changes, but not the whole field.

If someone could point me in the right direction that would be great!

Many thanks

<?php require_once('Connections/iwalletc_localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_iwalletc_localhost, $iwalletc_localhost);
$query_prop_apartments = "SELECT * FROM property_types WHERE property_types.prop_type = 'Private Apartments'";
$prop_apartments = mysql_query($query_prop_apartments, $iwalletc_localhost) or die(mysql_error());
$row_prop_apartments = mysql_fetch_assoc($prop_apartments);
$totalRows_prop_apartments = mysql_num_rows($prop_apartments);

mysql_select_db($database_iwalletc_localhost, $iwalletc_localhost);
$query_prop_landed = "SELECT * FROM property_types WHERE property_types.prop_type = 'Landed Property'";
$prop_landed = mysql_query($query_prop_landed, $iwalletc_localhost) or die(mysql_error());
$row_prop_landed = mysql_fetch_assoc($prop_landed);
$totalRows_prop_landed = mysql_num_rows($prop_landed);

mysql_select_db($database_iwalletc_localhost, $iwalletc_localhost);
$query_prop_hdb = "SELECT * FROM property_types WHERE property_types.prop_type = 'Hdb Flat'";
$prop_hdb = mysql_query($query_prop_hdb, $iwalletc_localhost) or die(mysql_error());
$row_prop_hdb = mysql_fetch_assoc($prop_hdb);
$totalRows_prop_hdb = mysql_num_rows($prop_hdb);

mysql_select_db($database_iwalletc_localhost, $iwalletc_localhost);
$query_prop_commercial = "SELECT * FROM property_types WHERE property_types.prop_type = 'Commercial'";
$prop_commercial = mysql_query($query_prop_commercial, $iwalletc_localhost) or die(mysql_error());
$row_prop_commercial = mysql_fetch_assoc($prop_commercial);
$totalRows_prop_commercial = mysql_num_rows($prop_commercial);

mysql_select_db($database_iwalletc_localhost, $iwalletc_localhost);
$query_prop_Hudc = "SELECT * FROM property_types WHERE property_types.prop_type = 'Hudc Apartments'";
$prop_Hudc = mysql_query($query_prop_Hudc, $iwalletc_localhost) or die(mysql_error());
$row_prop_Hudc = mysql_fetch_assoc($prop_Hudc);
$totalRows_prop_Hudc = mysql_num_rows($prop_Hudc);




?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testing saletype</title>
<script type="text/javascript">
// <![CDATA[
function display(obj,id1,id2, id3, id4, id5) {
txt = obj.options[obj.selectedIndex].value;
document.getElementById(id1).style.display = 'none';
document.getElementById(id2).style.display = 'none';
document.getElementById(id3).style.display = 'none';
document.getElementById(id4).style.display = 'none';
document.getElementById(id5).style.display = 'none';
if ( txt.match(id1) ) {
document.getElementById(id1).style.display = 'block';
}
if ( txt.match(id2) ) {
document.getElementById(id2).style.display = 'block';
}
if ( txt.match(id3) ) {
document.getElementById(id3).style.display = 'block';
}
if ( txt.match(id4) ) {
document.getElementById(id4).style.display = 'block';
}
if ( txt.match(id5) ) {
document.getElementById(id5).style.display = 'block';
}
}
// ]]>
</script>
</head>

<body>
<form id="proptype" name="proptype" method="post" action="saletype_test_parse.php">
  <table width="800" border="0" cellspacing="1" cellpadding="1">
    <tr>
      <td width="321"><label for="prop_type"></label>
        <label for="prop_type"></label>
        <select name="prop_type" onchange="display(this,'Private Apartments','Landed Property', 'Hdb Flat', 'Commercial', 'Hudc Apartments');">
          <option selected="selected">Please Select</option>
          <option value="Private Apartments">Private Apartments</option>
          <option value="Landed Property">Landed Property</option>
          <option value="Hdb Flat">Hdb Flat</option>
          <option value="Commercial">Commercial </option>
          <option value="Hudc Apartments">Hudc Apartments </option>
           <option value="invisible">Invisible</option>
      </select></td>
      </tr>
       <tbody id="Private Apartments" style="display: none;">
    <tr>
      <td><label for="prop_saletype1"></label>
        <select name="prop_saletype1" id="prop_saletype1">
          <?php
do {  
?>
          <option value="<?php echo $row_prop_apartments['prop_saletype']?>"><?php echo $row_prop_apartments['prop_saletype']?></option>
          <?php
} while ($row_prop_apartments = mysql_fetch_assoc($prop_apartments));
  $rows = mysql_num_rows($prop_apartments);
  if($rows > 0) {
      mysql_data_seek($prop_apartments, 0);
	  $row_prop_apartments = mysql_fetch_assoc($prop_apartments);
  }
?>
      </select></td> 
      </tbody >
 
  <tbody id="Landed Property" style="display: none;">    
   
      <td><label for="prop_saletype2"></label>
        <select name="prop_saletype2" id="prop_saletype2">
          <?php
do {  
?>
          <option value="<?php echo $row_prop_landed['prop_saletype']?>"><?php echo $row_prop_landed['prop_saletype']?></option>
          <?php
} while ($row_prop_landed = mysql_fetch_assoc($prop_landed));
  $rows = mysql_num_rows($prop_landed);
  if($rows > 0) {
      mysql_data_seek($prop_landed, 0);
	  $row_prop_landed = mysql_fetch_assoc($prop_landed);
  }
?>
      </select></td>
    <tbody id="Hdb Flat" style="display: none;"> 
   
      <td><label for="prop_saletype3"></label>
        <select name="prop_saletype3" id="prop_saletype3">
          <?php
do {  
?>
          <option value="<?php echo $row_prop_hdb['prop_saletype']?>"><?php echo $row_prop_hdb['prop_saletype']?></option>
          <?php
} while ($row_prop_hdb = mysql_fetch_assoc($prop_hdb));
  $rows = mysql_num_rows($prop_hdb);
  if($rows > 0) {
      mysql_data_seek($prop_hdb, 0);
	  $row_prop_hdb = mysql_fetch_assoc($prop_hdb);
  }
?>
      </select></td>
    <tbody id="Commercial" style="display: none;">
   
      <td><label for="prop_saletype4"></label>
        <select name="prop_saletype4" id="prop_saletype4">
          <?php
do {  
?>
          <option value="<?php echo $row_prop_commercial['prop_saletype']?>"><?php echo $row_prop_commercial['prop_saletype']?></option>
          <?php
} while ($row_prop_commercial = mysql_fetch_assoc($prop_commercial));
  $rows = mysql_num_rows($prop_commercial);
  if($rows > 0) {
      mysql_data_seek($prop_commercial, 0);
	  $row_prop_commercial = mysql_fetch_assoc($prop_commercial);
  }
?>
      </select></td>
      <tbody id="Hudc Apartments" style="display: none;">
      
      <td><label for="prop_saletype5"></label>
        <select name="prop_saletype5" id="prop_saletype5">
          <?php
do {  
?>
          <option value="<?php echo $row_prop_Hudc['prop_saletype']?>"><?php echo $row_prop_Hudc['prop_saletype']?></option>
          <?php
} while ($row_prop_Hudc = mysql_fetch_assoc($prop_Hudc));
  $rows = mysql_num_rows($prop_Hudc);
  if($rows > 0) {
      mysql_data_seek($prop_Hudc, 0);
	  $row_prop_Hudc = mysql_fetch_assoc($prop_Hudc);
  }
?>
      </select></td>
      </tr>
    <tr>
      <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
      
      
    </tr>
  </table>
</form>
</body>
</html>
<?php
mysql_free_result($prop_apartments);

mysql_free_result($prop_landed);

mysql_free_result($prop_hdb);

mysql_free_result($prop_commercial);

mysql_free_result($prop_Hudc);


?>