Readme Posted March 26, 2014 Share Posted March 26, 2014 How to make this: RED BOX IF I Search "Mobile" and choose 2 letters. Then result is Mobile LG IF 5 letters then Nokia Must use LEN or something? <?php mysql_connect("localhost", "", "") or die("Error connecting to database: ".mysql_error()); mysql_select_db("data") or die(mysql_error()); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Search results</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div class="container"> <form action="search.php" method="GET"> Search: <input type="text" name="query" /> <input type="submit" value="Search" /> </form> <div> <label>Search categories</label> <select> <option value="1">Search all</option> <option value="2">2 letters</option> <option value="4">3 letters</option> <option value="5">4 letters</option> <option value="6">5 letters</option> <option value="7">6 letters</option> </select> </div> <?php $query = $_GET['query']; $min_length = 2; if(strlen($query) >= $min_length){ $query = htmlspecialchars($query); $query = mysql_real_escape_string($query); $raw_results = mysql_query("SELECT * FROM articles WHERE (`title` LIKE '%".$query."%') OR (`text` LIKE '%".$query."%')") or die(mysql_error()); if(mysql_num_rows($raw_results) > 0){ while($results = mysql_fetch_array($raw_results)){ echo "<p><h3>".$results['title']."</h3>".$results['text']."</p>"; } } else{ echo "No results"; } } else{ echo "Minimum length is ".$min_length; } ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/287313-php-search-from-database/ Share on other sites More sharing options...
jazzman1 Posted March 27, 2014 Share Posted March 27, 2014 Why do you want to make a search by string length? What about if the length of two or more devices match the actual number of characters in the string? Quote Link to comment https://forums.phpfreaks.com/topic/287313-php-search-from-database/#findComment-1474091 Share on other sites More sharing options...
Readme Posted March 27, 2014 Author Share Posted March 27, 2014 It come "crossword database". If you can, please help. Quote Link to comment https://forums.phpfreaks.com/topic/287313-php-search-from-database/#findComment-1474201 Share on other sites More sharing options...
Readme Posted March 28, 2014 Author Share Posted March 28, 2014 This is not possible? Quote Link to comment https://forums.phpfreaks.com/topic/287313-php-search-from-database/#findComment-1474353 Share on other sites More sharing options...
mac_gyver Posted March 29, 2014 Share Posted March 29, 2014 your <select> menu has two apparent problems - 1) you must give the select menu a name attribute so that the value will have a name when it is submitted. 2) your select menu is not inside your <form></form>, so it won't get submitted anyway. your php code doesn't have anything in it to get, validate, and use the value from the length select menu, but once it does, you would probably want to use the mysql CHAR_LENGTH(str) function in your sql query to match only text field lengths that have the specific length that was selected - http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_char-length Quote Link to comment https://forums.phpfreaks.com/topic/287313-php-search-from-database/#findComment-1474373 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.