Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySQL search query using form select

  • 19-09-2006 4:01pm
    #1
    Closed Accounts Posts: 2,175 ✭✭✭


    Ok, so I have a DB populated with "stuff", and I have a page which includes the below form. Alot of the values are made up for security in this example, but you get the gist. There is a java reference in there also. It's to do with populating the town field when a county is selected.
    What I can't figure out is the "salesquery.php" tbh. I can't figure out how to process this form as I'm a n00b... :o
    <form name="form1" method="get" action="salesquery.php">
              
              <table width="100%" border="0" cellpadding="10"  
    
    align="center">
                <tr>
                  <td><font face="Arial, Helvetica, sans-serif"><b>Select 
    
    County:</b></font></td>
                  <td><select name='county' id='countySelect' 
    
    onchange='populateState()'>
                  </select>
       		</td>
            
                </tr>
                <tr>
                  <td><font face="Arial, Helvetica, sans-serif"><b>Select 
    
    Area:</b></font></td>
                  <td><select name='town' id='townSelect'>
                        </select>
            <script type="text/javascript">initCounty('DUBLIN'); </script></td>
                </tr>
                <tr>
                  <td><font face="Arial, Helvetica, sans-serif"><b>No. 
    
    Bedrooms:</b></font></td>
                  <td><select name="num">
                    <option selected value="0">Any Number</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                  
                  </select></td>
                </tr>
                <tr>
                  <td><font face="Arial, Helvetica, 
    
    sans-serif"><b>Price:</b></font></td>
                  <td><select name="minprice">
                    <option selected value="0">Any Price</option>
                    <option value="100000">100,000</option>
                    <option value="150000">150,000</option>
                    <option value="200000">200,000</option>
                
                  </select>
                    <font face="Arial, Helvetica, sans-serif"><b>to
                    <select name="maxprice">
                      <option selected value="0">Any Price</option>
                      <option value="100000">100,000</option>
                      <option value="150000">150,000</option>
                      <option value="200000">200,000</option>
                      
                    </select>
                    </b></font></td>
                </tr>
                <tr>
                  <td><font face="Arial, Helvetica, 
    
    sans-serif"><b>Type:</b></font></td>
                  <td><select name="type">
                    <option selected value="0">Any Type</option>
                    <option value="yoke">Yoke</option>
                    <option value="thing">Thing</option>
                    <option value="bevee">Bevee</option>
                    <option value="dodah">Dodah</option>
                    <option value="fasmasach">Fasmasach</option>
                  </select></td>
                </tr>
                <tr>
                  <td><input type="submit" name="Submit" 
    
    value="Search"></td>
                  <td>&nbsp;</td>
                </tr>
              </table>
              </form>
    
    Below is the start of the "salesquery.php". I think it's starting right. But I've done as much as I can figure out.
    <?PHP
    
    //Database Information
    include("connect.inc");
    
    
    
    //Connect to database
    
    mysql_connect ( $dbhost, $dbuser, $dbpassword)or die("Could not 
    
    connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    
        
    $county = $_POST['county'];
    $town = $_POST['town'];
    $num = $_POST['num'];
    $min_price = $_POST['minprice'];
    $max_price = $_POST['maxprice'];
    $type = $_POST['type'];
    
    //This is prob completely wrong
    $query= "SELECT * FROM sales WHERE county= '$county' 
    	AND town= '$town' 
    	AND price BETWEEN '$min_price' AND '$max_price' 
    	AND type ='$type' 
    	AND num= '$num'";
    
    $result = MYSQL_QUERY($query);
    
    //and on from here.....
    
    ?>
    
    

    Thanks a million guys. Any help appreciated.


Comments

  • Closed Accounts Posts: 583 ✭✭✭monkey tennis


    Well for a start, you're using different form submission methods. Your form uses 'GET', but your php script expects 'POST'. If you change the $_POST[]s in your php script to $_REQUEST[]s, you can use either (handy for debugging).

    My SQL's rusty as garden shears, so I can't help there.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    In theory the select sql should work. What do you want to do with the data after that? Presumably you want to print it? A simple example of how to do that would be after your sql query put:

    [php]while($row = mysql_fetch_array($result, MYSQL_ASSOC)){

    print("<tr>");
    print("<td> ".$row."</td>");
    print("<td> ".$row."</td>");
    print("<td> ".$row."</td>");
    print("<td> ".$row."</td>");
    print("<td> ".$row."</td>");
    print("</tr>");

    }
    [/php]

    Other than that what were you hoping to do?


  • Closed Accounts Posts: 2,175 ✭✭✭chamlis


    Yeah print it on a results page. I just don't know the commands. I mean, a results page is something that is generated depending on user input, right? The logstics of that have me a bit confused, like how does one ensure it looks well on a page (I see you have put in table tags). I have a page design that utilises a header, a footer, and a main body. The main body has a menu collume on the left, and a collume on the right. The center part is where all the pages differ. So in order for the results page to be generated, must I say "print the whole lot of the page code with these results" or can I just say "yeah, you results should fit neatly into THIS part in the middle here..."

    I have no problem printing results to blank page, like in the examples I've followed. Does any of this make sense?


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    It makes perfect sense. That's often the way things work, though obviously everyone to their own way! I think the easist way for someone such as yourself is to keep the two seperate. So create your html page(assuming your pages are mostly html based?) and simply use the php 'include' function to insert salesquery.php into the html page.

    What method are you using for layout? Can you post an example of the layout of the "main content" section where the results are going?


Advertisement