Jump to content

Recommended Posts

Hello,

 

Following a little snippet I put together to search the database and return the results. Works just fine but I need it to work better  :shrug:

 

What I need it to do is to search the exact string and return the result with a message. The data is like: 52 67 87 99 34 with an id assigned to it that's like: 12345

 

So basically search the row for an exact match of such 2 digit x 5 sets of data (not by the ID). I am getting results but I can type in any digit and as long as it's present it in any row including the ID row, it returns all the results. SO.... I am trying to accomplish the following:

 

  • Search for an exact set of numbers (not including the ID for the set)
  • Look for an exact match of the numbers
  • Return numbers, their id, and success message if found
  • Return nothing and fail message if not found

 

Here's the code:

 

<?php
mysql_connect ("localhost","xxxxxx","xxxxxx")  or die (mysql_error());
mysql_select_db ("numbersets");

$number = $_POST['number'];

$result = mysql_query("select * from numbersets where numbers like '%$number%' or numid like '%$number'");


while ($row = mysql_fetch_array($result))

{
    echo '<br /> Your Numbers: '.$row['numbers'];
    echo '<br /> ID Number: '.$row['numid'];
    echo '<br/><br/>';
    }

?>

<?php
$reasons = array();
function is_valid($numbers)
{
    global $reasons;
    if ( TRUE ) $reasons[] = 'WE HAVE A MATCH';
    if ( FALSE ) $reasons[] = 'SORRY NO RESULTS';
    if ( count($reasons) == 0 )
        return TRUE;
    else
        return FALSE;
}

if (!is_valid(TRUE))
{
    foreach($reasons as $reason)
        echo $reason, '<br />';
}

if (!is_valid(FALSE))
{
    echo '<br />';
}
?>

 

Here's the form:

 

    <form action="searchFunction.php" method="post">
     Your Numbers: 
     <br /> <br />
     <input type="text" name="number" class="iinputnum" maxlength="2"/>  
     <input type="text" name="number" class="iinputnum" maxlength="2"/>
     <input type="text" name="number" class="iinputnum" maxlength="2"/>
     <input type="text" name="number" class="iinputnum" maxlength="2"/>
     <input type="text" name="number" class="iinputnumred" maxlength="2"/>
     <br />
    <input type="submit" name="submit" value="Search" class="submitButton"/>
    </form>

 

Thanks so much for any help! :)

Link to comment
https://forums.phpfreaks.com/topic/239803-search-results-and-message-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.