Dropdown menu search output to HTMl/PHP page, questions..

Discussion in 'PHP' started by nullpoint81, Oct 20, 2011.

  1. #1
    :confused:

    First post on the site, just read the FAQ (and I did!).

    Basically, what I would like to do is have a page with two dropdown forms. The first includes days of the week. The second includes times of the day. A third textbox (boolean) search would be nice as well as maybe some checkboxes to help filter, but those are unimportant at this point.

    The point of this script would be to output different venues onto an HTML/PHP into a grid or table by selecting data from each of the two search boxes.

    I have a SQL database created already, with all of the necessary tables, rows, columns laid out. I'm mostly just looking for some help in creating the search script, or even if someone has heard of s code snippet that may be available that does the same or similar thing.

    I can provide my failure of coding thus far, but would much prefer to start fresh.

    Anyway, thanks in advance for the help. I can provide any info if any is needed.
     
    nullpoint81, Oct 20, 2011 IP
  2. Divided

    Divided Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    3
    Trophy Points:
    0
    #2
    Let's have a look at the code so far, it helps see how far along you are already!
     
    Divided, Oct 21, 2011 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    What you need depends on your level of expertise in writing the program. Is:

    "send the user's selections to a PHP page via AJAX to construct a SELECT query and return the results"

    enough for you? Or do you need the pages completely written for you? Or somewhere between the two extremes?
     
    Rukbat, Oct 21, 2011 IP
  4. nullpoint81

    nullpoint81 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ah, that does make sense Rukbat.

    Well, sorry for the delay - here's what I'm working with so far. It's a total disaster. It does return results, but they are not quite what I'm looking for.

    
    <?php
    
    $dbHost = 'localhost'; 
    
    $dbUser = '_______'; 
    $dbPass = '_______';
    $dbDatabase = '________'; 
    $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error());
    
    mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
    
    
    $error = array();
    $results = array();
    $dropdown = empty($_POST['searchForm']);
    
    
    if (isset($_GET['search'])) {
       $searchTerms = trim($_GET['search']);
       $searchTerms = strip_tags($searchTerms); // remove any html/javascript.
       
       if (strlen($searchTerms) < 0) {
          $error[] = "Search must include at least one character, I mean come on...";
       }else {
          $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
       }
       
       
       if (count($error) < 1) {
          $searchSQL = "SELECT id, name, address, url, 08000900, 09001000 FROM bingo WHERE ";
          
    
          $types = array();
    
    	  $types[] = isset($_GET['name'])?"`name` LIKE '%{$searchTermDB}%'":'';
    	  $types[] = isset($_GET['08000900'])?"`08000900` LIKE '%{$searchTermDB}%'":'';
          
          $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)
          
          if (count($types) < 1)
             $types[] = "`name` LIKE '%{$searchTermDB}%'"; // use the name as a default search if none are checked
          
          $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `address`"; // order by title.
    
          $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}");
          
          if (mysql_num_rows($searchResult) < 1) {
             $error[] = "The search term provided {$searchTerms} yielded no results.";
          }else {
             $results = array(); // the result array
             while ($row = mysql_fetch_assoc($searchResult)) {
                $results[] = "{$i}: {$row['address']}<br />{$row['url']}<br />{$row['name']}<br />{$row['wifi']}<br /><br />";
             }
          }
       }
    }
    
    function removeEmpty($var) {
       return (!empty($var)); 
    }
    ?>
    
    Code (markup):
    Basically, the search terms are based on military time starting at 8AM and ending at 2AM. I have yet to enter the days of the week.

    And here's the form (I'm testing the 08000900 and 09001000 times currently, the rest are placeholders):

     
    
    <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?>
          <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm">
             <select size="1" name="searchForm">
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="09001000" name="09001000" <?php echo isset($_GET['09001000']); ?> />9AM-10AM</option>
             <option value="10001100" name="10001100" <?php echo isset($_GET['10001100']); ?> />10AM-11AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             <option value="08000900" name="08000900" <?php echo isset($_GET['08000900']); ?> />8AM-9AM</option>
             </select> 
             <input type="submit" name="submit" value="Search" />
          </form>
    
    Code (markup):
    I'd be pretty happy if I could output even one of the times, because from there it's a matter of fill in the blank and to make it pretty with CSS. PHP is not my strong suit... :(
     
    nullpoint81, Oct 25, 2011 IP
  5. nullpoint81

    nullpoint81 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Bump...........
     
    nullpoint81, Nov 6, 2011 IP
  6. uocnv

    uocnv Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #6
    Thanks for help me . : up to 20 characters :))
     
    uocnv, Nov 7, 2011 IP
  7. nullpoint81

    nullpoint81 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hah, well no problem I guess.

    I've decided to go another route with this script - the new version is working AWESOME.
     
    nullpoint81, Nov 11, 2011 IP