Jump to content

Archived

This topic is now archived and is closed to further replies.

KateS

select menu option as a variable

Recommended Posts

Can anyone help to save me from an untimely and possibly violent demise and point my owner to where she can find out how to use a select menu in Dreamweaver, which when the user has selected an option will display results from a mysql database in a separate table on the same page? She has tried numerous different ways of doing this and although parts of the script have worked it has not worked fully. She has followed the help menu in dreamweaver, various books on php and mysql and before she ends up throwing me out of the window can someone help me? Please, I'll love you forever, Kate's Mac!

Share this post


Link to post
Share on other sites
I would prefer it to use the displayed option and update itself rather than have the user click a submit button but at this stage anything would be useful as i have been unable to get either to work.

Share this post


Link to post
Share on other sites
put onChange="document.myform.submit()" in the dropdown list

it would also be helpful if you can show us some of your code.

Share this post


Link to post
Share on other sites
and then to find what they want displayed use a switch command...then queary the database and display the results

Share this post


Link to post
Share on other sites
Have tried using onChange="document.forms['Businesses'].submit()" but that didn't work. I have tried using a variable to store the information from the selected option but it doesn't recognise it. Also as I have been working on this now for quite some time there is the chance that I have screwed something up as I have changed something else as I am getting a mysql syntax error message for a line which has only a <tr> tag on it.

Share this post


Link to post
Share on other sites
This is the code that I tried last but I have tried various different ways. SearchString was the name that I had for the variable for the menu result.

<?php
            $SearchString_DriffieldRS = "-1";
if (isset($_GET['SearchString'])) {
  $SearchString_DriffieldRS = (get_magic_quotes_gpc()) ? $_GET['SearchString'] : addslashes($_GET['SearchString']);
}
mysql_select_db($database_myTownQuery, $myTownQuery);
$query_DriffieldRS = "SELECT * FROM Businesses WHERE Businesses.town='Driffield' and Businesses.business_type='".chop($_GET['SearchString'])."'' ORDER BY Businesses.business_name";
$DriffieldRS = mysql_query($query_DriffieldRS, $myTownQuery) or die(mysql_error());
$row_DriffieldRS = mysql_fetch_assoc($DriffieldRS);
$totalRows_DriffieldRS = mysql_num_rows($DriffieldRS);
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" name="Businesses">
     
          <select name="SearchString" title="<?php echo chop($_GET['SearchString']); ?>" onChange="document.forms['Businesses'].submit()"> 
            <option selected>Please select</option>
            <option value="Accountants">Accountants</option>
            <option value="Acupuncture">Acupuncture</option>
            <option value="Advertising Services">Advertising Services</option>
            <option value="Agricultural Services">Agricultural Services</option>
           
          </select> 
      </form>       
         
                  <?php if ($totalRows_DriffieldRS > 0) { // Show if recordset not empty ?>
                  <?php echo chop($_GET['SearchString']); ?><br>
                  <?php do { ?>
                  <?php echo $row_DriffieldRS['business_type']; ?><br>
                  <?php echo $row_DriffieldRS['business_name']; ?>&nbsp;<?php echo $row_DriffieldRS['first_name']; ?> <?php echo $row_DriffieldRS['last_name']; ?> <?php echo $row_DriffieldRS['address1']; ?> <?php echo $row_DriffieldRS['address2']; ?> <?php echo $row_DriffieldRS['town']; ?> <?php echo $row_DriffieldRS['county']; ?> <?php echo $row_DriffieldRS['postcode']; ?><br>
                  <?php echo $row_DriffieldRS['tel_no_01']; ?>&nbsp;<?php echo $row_DriffieldRS['tel_no_02']; ?><br>
                  <br>
                  <?php } while ($row_DriffieldRS = mysql_fetch_assoc($DriffieldRS)); ?>
                  <?php } // Show if recordset not empty ?>
              <?php
mysql_free_result($DriffieldRS);
?>

Share this post


Link to post
Share on other sites
k heres a simple way to do it if the user clicks submit menu name is menu and sbmit name is submit! I think this would also work into the onchange but im not 100% sure how to configure it!



[code]if(isset($_POST['submit'])){
$menu=$_POST['menu'];

switch($menu){
case "Pizza":
//run query here
break;

case "cookies":
///blah blah
break;
//so on and so fourth the word in the quotes is the value of the option in the menu.....
}
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.