Jump to content

select menu option as a variable


KateS

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!
Link to comment
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.
Link to comment
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);
?>

Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.