aug Posted June 19, 2011 Share Posted June 19, 2011 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 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! Quote Link to comment https://forums.phpfreaks.com/topic/239803-search-results-and-message-help/ Share on other sites More sharing options...
fugix Posted June 19, 2011 Share Posted June 19, 2011 Firstly, set unique names for each input, and adjust your code accordingly. Then repost your code Quote Link to comment https://forums.phpfreaks.com/topic/239803-search-results-and-message-help/#findComment-1231866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.