Skip to main content
Inspiring
September 14, 2012
Question

dynamic select list display details on same page

  • September 14, 2012
  • 1 reply
  • 5311 views

i have a select dropdown list that is showing products from a php msql database. When one of the products is selected from the list in need the details of that product displayed underneath the select list.

here is what i have so far

mysql_select_db($database_beau, $beau);

$query_Recordset1 = "SELECT * FROM beaProdSizes, beauCat WHERE beaProdSizes.CatID = beauCat.catID";

$Recordset1 = mysql_query($query_Recordset1, $beau) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

<select id="selectName" name="name">

                      <option value="Select Design">Select Design</option>

                      <?php

do {

?>

                      <option value="<?php echo $row_Recordset1['name']; ?>"><?php echo $row_Recordset1['name']; ?></option>

                      <?php

} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));

  $rows = mysql_num_rows($Recordset1);

  if($rows > 0) {

      mysql_data_seek($Recordset1, 0);

            $row_Recordset1 = mysql_fetch_assoc($Recordset1);

  }

?>

                      </select>

thanks in advance

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
September 14, 2012

You will need to edit the Recordset code to include a conditional statement. This will prevent you from Dreamweaver recognizing the recordset, but it should still work if you are careful how you make the changes.

First of all, wrap the <select> menu in a form, and set the form's method to GET, and the action to the current page.

Also add a submit button to the form.

Instead of storing the name as the value of each <option> element, you need to store the catID:

<option value="<?php echo $row_Recordset1['catID']; ?>"><?php echo $row_Recordset1['name']; ?></option>

Edit the recordset code like this:

mysql_select_db($database_beau, $beau);

$query_Recordset1 = "SELECT * FROM beaProdSizes, beauCat WHERE beaProdSizes.CatID = beauCat.catID";

if (isset($_GET['catID']) && is_numeric($_GET['catID'])) {

    $query_Recordset1 .= ' AND beauCat.catID = ' . $_GET['catID'];

}

$Recordset1 = mysql_query($query_Recordset1, $beau) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

Inspiring
September 14, 2012

ok i have added the above code but could you tell me how i show the product content below the select menu?

thanks in advance

Inspiring
September 14, 2012

this is how the php content looks now

<?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;

}

}

$var1_Recordset1 = "-1";

if (isset($_GET['CatID'])) {

  $var1_Recordset1 = $_GET['CatID'];

}

mysql_select_db($database_beau, $beau);

$query_Recordset1 = sprintf("SELECT * FROM beaProdSizes, beauCat WHERE beaProdSizes.CatID = beauCat.catID AND beauCat.catID=%s", GetSQLValueString($var1_Recordset1, "int"));

if (isset($_GET['catID']) && is_numeric($_GET['catID'])) {

    $query_Recordset1 .= ' AND beauCat.catID = ' . $_GET['catID'];

}

$Recordset1 = mysql_query($query_Recordset1, $beau) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);$var1_Recordset1 = "-1";

?>