Results 1 to 4 of 4
  1. #1

    how to have three search keys in php?

    Here is the html template:
    <!DOCTYPE html>
    <html dir="ltr" lang="en-US" >
    <meta charset="UTF-8" />

    <div id="header" style="background-color:#FFA500;">
    <h1 style="margin-bottom:0;">rinex data archive </h1></div>

    <div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">

    define("GREETING", "Welcome ", true);
    echo greeting;

    <form action="hr.php" method="get">
    <input type="text" name="keyname" />
    <input type="submit" value="Search" />
    <div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">

    Here is the php code i need to have three search keys one for the file name
    and two as a range to select for example i need t serach files abc00.00 to abc10.10 how do i do this?


    //capture search term and remove spaces at its both ends if the is any
    $searchTerm = trim($_GET['keyname']);

    //check whether the name parsed is empty
    if($searchTerm == "rinex_file")
    echo "Enter name you are searching for.";

    //database connection info
    $host = "localhost"; //server
    $db = "ri"; //database name
    $user = "m"; //dabases user name
    $pwd = "c"; //password

    //connecting to server and creating link to database
    $link = mysqli_connect($host, $user, $pwd, $db);

    //MYSQL search statement
    $query = "SELECT * FROM ri WHERE rinex_file LIKE '%$searchTerm%'";

    $results = mysqli_query($link, $query);

    /* check whethere there were matching records in the table
    by counting the number of results returned */
    if(mysqli_num_rows($results) >= 1){
    echo '<table border="1">
    <th>rinex version</th>
    <th>maker name</th>

    <th>maker number</th>
    <th>rinex file</th>
    while($row = mysqli_fetch_array($results)){

    echo '<tr>

    echo '</table>';


    echo "There was no matching record for the name " . $searchTerm;

    Last edited by madu; 10-07-2013 at 03:39 AM.

  2. #2
    Just add two more input fields, fetch them all into variables the same as the one you already have, and then do a loop from the lower-bound to the upper-bound. In the loop, construct either an IN clause or a chain of LIKE / OR LIKE clauses for your SQL query. For example, the inputs might be:

    searchterm: beans
    lower bound: 11
    upper bound: 99

    You would loop through valid values and construct a string like:

    in ('beans.11.11', 'beans.12.12' ... ... ... 'beans.99.99')

    Since you are using LIKE as your comparison operator (which makes sense for a text search), you would modify the above because LIKE and IN can't be combined as far as I know. So instead you would construct:

    fieldname LIKE "%beans.11.11%" OR fieldname LIKE "%beans.12.12%"
    ...etc, on through to the upper bound.

    From there it's just making sure the UI, and your looping code, speak the same language about proper input for the selection boundary. e.g., if they're all numbers that's perfect. If they're some other values, you'll not only need to sanitize them, but a way to determine how those values comprise a sequence which can have an upper and lower selection boundary -- you can accomplish both with a PHP array containing all valid inputs, in sequence.

    Don't forget to protect those inputs from SQL injections before you make it live, by the way!

  3. #3
    could you help me with the query as to where and how do i implement the loop for the upper and lower bounds?

  4. #4
    No. Respectfully, I'm sorry, but I can't teach you PHP for free, nor do your project for you for free.

Similar Threads

  1. Alternate Keys for Arrow Keys?
    By webson in forum Web Hosting Lounge
    Replies: 4
    Last Post: 09-20-2013, 09:19 PM
  2. Replies: 0
    Last Post: 08-11-2010, 05:18 AM
  3. MySQL's foregin keys cannot be extracted via PHP
    By ProbablyX in forum Programming Discussion
    Replies: 6
    Last Post: 04-22-2008, 05:34 PM
  4. Using quote marks to group search keys
    By dbryant in forum Programming Discussion
    Replies: 1
    Last Post: 07-09-2004, 12:11 AM

Posting Permissions

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