开发者

get data from 2 dropdownlist after submitting the form in php

开发者 https://www.devze.com 2023-03-07 14:04 出处:网络
Ive been searching around here to find an answer but I cannot find one :). My issue I have 2 dropdownlist \"manufacturers\" and \"models\". This is for an aircraft directory. What I want is after the

Ive been searching around here to find an answer but I cannot find one :). My issue I have 2 dropdownlist "manufacturers" and "models". This is for an aircraft directory. What I want is after the user select a manufacturer and model and click "submit", they will be redirected to a page and show the information about a certain aircraft that belongs to that certain manufacturer and model. Just for clarification, I want to show that data after the user click the submit button. I saw a lot of tutorials about getting data from the dropdownlist but all of them used "onchange" for getting and displaying the value from the dropdownlist.

here is the code:

<form name="psform" action="pistonsingle.php" method="post">
         <?php 
            $display = displaymaincat(1);
            while($result=mysql_fetch_array($display)){
                echo $result['maincategory'];  
            }
          ?>
         <?php 
           $display = mysql_query("SELECT * FROM manufacturers");
            confirm_query($display);
            echo "<select name=\"manu\">";
            echo "<option> --Select Manufacturer--</option>";
            while($result=mysql_fetch_array($display)){
             echo "<option value=$result[id]>$result[manufacturer] </option>";};
             echo "</select>";
         ?>
         <?php 
             $display = mysql_query("SELECT * FROM models");
            confirm_query($display);
            echo "<select name=\"models\">";
             echo "<option name=\"nullsel\"> --Select Model--</option>";
            while($result=mysql_fetch_array($display)){
             echo "<option value=$result[id]>$result[model] </option>";};
             echo "</select>";
         ?>
         <input type="submit" name="psbutton" id="button" value="Show Listing"  />
         </form>

Then I try to use this function that i make on the action page function psdisplay(){

        if(isset($_POST['submit'])){
        $display = mysql_query("SELECT * FROM individualaircraft 
        INNER JOIN aircraftmaincat on individualaircraft.maincategory_id = aircraftmaincat.id
        INNER JOIN manufacturers on individualaircraft.manufacturer_id = manufacturers.id
        INNER JOIN models on individualaircraft.model_id = models.id
        WHERE maincategory_id = 1");
        confirm_query($display);
        return $display;
    }
        }

?></td>
<td><?php 
        $display = psdisplay();
        while($result=mysql_fetch_array($display)){
            echo $result['generalinformation'];
        }
?></td>
<td><?php 
    $display = psdisplay();
        while($result=mysql_fetch_array($display)){
            echo $result['website'];
        }

?></td>

its working. it displays the data but the prob开发者_JAVA技巧lem is when the user click the submit button even he/she select a certain manufacturer or model, what my code do is just display all the aircrafts and not a certain aircraft that belong to a certain manufacturer and model.

I hope somebody can help me :). Thanks in advance.

Keyframer


Hey I don't see anywhere that you actually use the models and manufacturers values. You don't use them in your sql query in the psdisplay() function thats for sure. This might be more what you need.

function psdisplay($manufacturer, $model)
        $display = mysql_query("SELECT * FROM individualaircraft 
        INNER JOIN aircraftmaincat on individualaircraft.maincategory_id = aircraftmaincat.id
        INNER JOIN manufacturers on individualaircraft.manufacturer_id = " . mysql_real_escape_string($manufacturer) . "
        INNER JOIN models on individualaircraft.model_id = " . mysql_real_escape_string($model) . "
        WHERE maincategory_id = 1") or die(mysql_error());
        confirm_query($display);
        return $display;
}

Then change this code to this:

<td><?php 
$display = psdisplay($_POST['manu'], $_POST['model']);
while($result=mysql_fetch_array($display)){
    echo $result['generalinformation'];
}
?></td>

Oh and if this does work for you, don't forget to add some validation and also escape the variables in the sql query :)

0

精彩评论

暂无评论...
验证码 换一张
取 消