Jump to content

Archived

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

kristy7

display data from multiple dynamic dropdowns

Recommended Posts

Hi All,

I am pretty much a newbie when it comes to php and mysql. I am having trouble doing a job for work where I have multiple drop down boxes attached to a mysql database, each linked to a separate table. I want to select an option from each dropdown and generate a query which will search another table that all the dropdown tables are linked to and give me the data selected and print to a new page.

I have the dropdowns working I am just not sure how to do the query to incorporate the user selected options and print it to a new page, any help would be much appreciated, this is the gist of what I have so far....

// set up form for selecting required soil type
print "<form>";
print "<center>";
print "<table height=20 cellSpacing='0' cellPadding='5' border='2' width='30%' bgColor='#DFF7FF' >";
print "<tr>";
print " <td width='30%'> <font face='Arial' size='2'>Pool Type:</font></td>";
print " <td width='*'>";
print " <select NAME='soil Type' ID='soilType' onChange='displayProcedure(this.form)'> '\n";
print " <option value='nil'> Choose a soil Type .... \n";

// connect and execute query

$query = "SELECT soilType FROM soilType ORDER BY soilType ";
$resulta = mysql_query($query, $dbcnx) or die ("Database query error: " . mysql_error());
while ( $a_row = mysql_fetch_object($resulta) )
{
print "<option value='$a_row->soilType'> $a_row->soilType \n";
};
print "</select>";
print "</tr>";
print "</table>";
print "</form>";


this gives me my dropdown selection of soil type, I also have location and area, this info is linked to tblgrower which is the table I want to query. please help I have been fiddling with this for ages and can not get it, especially sending the result to a new page

Share this post


Link to post
Share on other sites
Guest askjames01
first make different computation each.
then call header.
then call include (include for different computation) to the option...

Share this post


Link to post
Share on other sites
[!--quoteo(post=368159:date=Apr 24 2006, 04:28 PM:name=askjames01)--][div class=\'quotetop\']QUOTE(askjames01 @ Apr 24 2006, 04:28 PM) [snapback]368159[/snapback][/div][div class=\'quotemain\'][!--quotec--]
first make different computation each.
then call header.
then call include (include for different computation) to the option...
[/quote]
I am sorry this doesn't mean anything to me could you please explain.....thankyou

Share this post


Link to post
Share on other sites
Well, your question is a bit hazy to me... but here goes:

When you form posts, you need to be able to handle it. Here's my rough tweak of your code.

[code]if($_POST) {
  $query = "SELECT `soilType` FROM `soilType` WHERE `soilType` = '".$_POST['soilType']."' ORDER BY `soilType`"; //changed your query
  $resulta = mysql_query($query, $dbcnx) or die ("Database query error: " . mysql_error());
  while ( $a_row = mysql_fetch_object($resulta) ) {
    print "<option value='$a_row->soilType'> $a_row->soilType \n";
  };
  print "</select>";
  print "</tr>";
  print "</table>";
  print "</form>";
} else {
  print "<form>";
  print "<center>";
  print "<table height=20 cellSpacing='0' cellPadding='5' border='2' width='30%' bgColor='#DFF7FF' >";
  print "<tr>";
  print " <td width='30%'> <font face='Arial' size='2'>Pool Type:</font></td>";
  print " <td width='*'>";
  print " <select NAME='soilType' ID='soilType' onChange='displayProcedure(this.form)'> '\n";
  print " <option value='nil'> Choose a soil Type .... \n";
}[/code]

but the question is a bit fuzzy -- if I've run off in the wrong direction, let me know.

Share this post


Link to post
Share on other sites
Hi Thanks for your reply, maybe I should make my question clearer. I have three separate user select drop down menus which are linking to the db fine. I really I have no idea how to display the data based on what the user has selected from the drop downs and to put it on a separte page. I have fiddled with my code so much now nothing seems to work and I am completly confussed.

Do I put the query to select from table where $resulta=$a and $resultb=$b and $resultc=$c below the print statement for the table to display the data or above it,

what will send the data from the query to another page??

this gives me my drop down fine when repeated for each selection type

$query = "SELECT soiltype FROM soiltype ORDER BY soiltype ";
$resulta = mysql_query($query, $dbcnx) or die ("Database query error: " . mysql_error());
while ( $a_row = mysql_fetch_object($resulta) )
{
print "<option value='$a_row->soiltype'> $a_row->soiltype \n";
};
print "</select>";
print "</tr>";
print "</table>";
print "</form>";

\\then the submit button

<form action="AddList.php" method="post">
<input type="submit" name="Submit" value="Submit" />
</form>

\\ then I can't get the query right that will take the three selected variables and return some data.

hope this is a little clearer, it is driving me insane, I know what I want to do is not difficult but I just can't seem to work it out

Share this post


Link to post
Share on other sites
PHP does stuff in the order you write it. So, first of all, you need to include the <select><option> stuff inside your <form> (which is standard HTML).

If you click "submit" the way it is, nothing will come through -- but, again, that's just the way HTML works, and really has nothing to do with PHP.

Second[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Do I put the query to select from table where $resulta=$a and $resultb=$b and $resultc=$c below the print statement for the table to display the data or above it,[/quote]
just do everything in logical sequence. You have to get the data before you can print it. printing it first and then getting it is exactly like putting the cart before the horse.

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.