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.

Recommended Answers

All 4 Replies

So what is your php problem?

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

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 :).

It works..!!
Tahnk you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.