Jump to content


Photo

select menu option as a variable


  • Please log in to reply
7 replies to this topic

#1 KateS

KateS
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 August 2006 - 05:31 PM

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!

#2 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 02 August 2006 - 05:39 PM

like display automaticly or after the user clicks submit? (like a search box)
"Syntax error" .. WHERE THE **** IS IT?!

#3 KateS

KateS
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 August 2006 - 05:42 PM

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.

#4 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 02 August 2006 - 05:42 PM

put onChange="document.myform.submit()" in the dropdown list

it would also be helpful if you can show us some of your code.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#5 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 02 August 2006 - 05:45 PM

and then to find what they want displayed use a switch command...then queary the database and display the results
"Syntax error" .. WHERE THE **** IS IT?!

#6 KateS

KateS
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 August 2006 - 05:49 PM

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.

#7 KateS

KateS
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 August 2006 - 05:55 PM

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



#8 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 02 August 2006 - 05:55 PM

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!



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.....
}
}

"Syntax error" .. WHERE THE **** IS IT?!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users