SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    1 Post(s)
    0 Thread(s)

    Calling a Range From MySQL Table With Drop Down Menu

    Good evening from Palo Alto, California. I have four items in a MYSQL database table. Each has 2 fields: name and weight, as shown here:

    Bob 149
    Sue 98
    Jack 155
    Sally 110

    I want users to be able to visit a drop-down menu and ask to see the names associated with one of three weight ranges: up to 100, between 100 and 150, and over 150. If, for example, they selected 100-150, I'd like the code to return:


    But I'm stuck on how to do this. I imagine that the HTML page with the drop down menu would look something like:

    <form action="generatelist.php" method="POST">
    Show me the names of people with weights of
    <select name="weight" size="1">
    <option value> </option>
    <option value="upto100">up to 100</option>
    <option value="100-150">100-150</option>
    <option value="150+">over 150</option>
    <INPUT TYPE="submit" value="Search"></FORM>

    I also imagine that "generatelist.php" should look something like:

    $weight = $_POST['weight'];
    mysql_connect("", "", "password") or die(mysql_error());
    @mysql_select_db("nameofdatabase") or die( "Unable to select database");
    $query="SELECT * FROM landforsale WHERE weight='WeightRange'";
    while ($i < $num) {
    <? echo "$name";?><br><br>

    Please, do you have some guidance for me? Thank you!

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Kathmandu, Nepal
    0 Post(s)
    0 Thread(s)
    Try out this code which working fine with me although this might not be the good way if someone expert finds easy and short way.
    PHP Code:
    $weight $_POST['weight'];
    $weight == "100"){
    $param " AND weight<100";
        else if(
    $weight == "100-150"){
    $param " AND weight>100 AND weight<150";
        }else if(
    $weight == "150"){
    $param " AND weight>150";
    $param "";
    $sql "SELECT * FROM tbltest WHERE 1 $param";
    $result mysql_query($sql);
    $rows mysql_fetch_array($result)){
    $rows['name1'] . "<br>";

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <form name="frm1" method="post">
    <table width="350" border="0" cellspacing="1" cellpadding="3">
        <td colspan="2" align="left" valign="middle">Select Weight </td>
        <td align="right" valign="middle">&nbsp;</td>
        <td><select name="weight" size="1">
            <option value="0">Select</option>
            <option value="100">Up To 100</option>
            <option value="100-150">100-150</option>
            <option value="150">Over 150</option>
          </select>    </td>
        <td align="right" valign="middle">&nbsp;</td>
        <td><input type="submit" name="Submit" value="Send Mail"></td>
        <td colspan="2" align="left" valign="middle">&nbsp;</td>
    Mistakes are proof that you are trying.....
    PSD to HTML - | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2006
    1 Post(s)
    0 Thread(s)

    Other suggestions? And thanks, rajug!

    Thank you, rajug, very much for your reply. The code seems not to be working for me. I wonder -- does someone see a simpler solution?
    Thank you!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts