0

I would like to know the best way to manage the two drop down menu on the PHP page.

1st menu : Select Type of House (House1, House2, )
2nd menu : Select Number of Rooms (1,2 .. 12)

The system should be displayed price based on selected items.

Need your suggestion for manage this system in order to make it easier for future use.

3
Contributors
4
Replies
11
Views
4 Years
Discussion Span
Last Post by PriteshP23
0

For instance, This is my code and i want to have out put like this:

You have selcted
Diagnostics: Terminites
Number of room = 3
Price is : 105

Thanks in advanced.

<html>
    <body>
        <form align="center" action="demo.php" method="post">        
            <br><br><br>Diagnostics:
            <select name="diagnostics">
            <option value="Amiante">Amiante</option>
            <option value="Terminites">Terminites</option>
            <option value="Plomb CREP">Plomb CREP</option>
            </select>        
            <br><br><br>Number of Room:
            <select name="room">
            <option value="95">1</option>
            <option value="100">2</option>
            <option value="105">3</option>
            <option value="110">4</option>
            </select>
            <br><br><br>
            <input type="submit" value="Valider">
        </form>
    </body>
</html>
<?php
    $diagnostics=$_POST['diagnostics'];
    $room=$_POST['room'];

    if ($diagnostics=="Plomb CREP" && $room=="95")
    {
        echo "Price for Plomb CREP : 120 " ; 
    }
        elseif ($diagnostics=="Plomb CREP" && $pieces=="100")
        {
             echo "Price for Plomb CREP : 140 " ;   
        }
        elseif ($diagnostics=="Plomb CREP" && $pieces=="105")
        {
            echo "Prix pour Plomb CREP : 160 " ;    
        }
        elseif ($diagnostics=="Plomb CREP" && $pieces=="110")
        {
             echo "Prix pour Plomb CREP : 180 " ;   
        }               
    else
    {
        echo "Diagnostics Price: ", $pieces;    
    }
?> 
0

Well you could write that a bit cleaner :). For example I'd use a switch (but maybe you should think about putting all this in a database).

<?php
$diagnostics = $_POST['diagnostics'];
$room = $_POST['room'];

if($diagnostics == 'Plomb CREP')
{
    switch($room)
    {
        case '95':
            $price = 120;
            break;
        case '100':
            $price = 140;
            break;

        // Etc.
    }

    echo 'Price for Plomb CREP: ' . $price . '<br/>';
}
else
    echo 'Diagnostics price: ' . $pieces . '<br/>';
?> 

But I'm still not 100% sure what you're trying to achieve. Maybe I can help you better if you'd be a little bit more specific :).

Edited by minitauros

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.