cary1234 Posted September 16, 2013 Share Posted September 16, 2013 Greetings, as what the title says I want to add search function to my website that looks like facebook (even if you dont press ENTER the result can be seen already and it searches for every letter combination ex. if I type 123 the result would be cary1234)I already tried searching to search in google the results are as follows1. http://www.9lessons.info/2009/06/autosuggestion-with-jquery-ajax-and-php.htmlI try to copy-paste the code, but they arent working. I also dont understand the code.2. http://www.codeforest.net/simple-search-with-php-jquery-and-mysql This link is much better I think, it doesnt give me exact facebook searching but the codes has comments so I can understand. Problem is I'm stuck in this code. <?php //if we got something through $_POST if (isset($_POST['search'])) { // here you would normally include some database connection include('db.php'); $db = new db(); // never trust what user wrote! We must ALWAYS sanitize user input $word = mysql_real_escape_string($_POST['search']); $word = htmlentities($word); // build your search query to the database $sql = "SELECT title, url FROM pages WHERE content LIKE '%" . $word . "%' ORDER BY title LIMIT 10"; // get results $row = $db->select_list($sql); if(count($row)) { $end_result = ''; foreach($row as $r) { $result = $r['title']; // we will use this to bold the search word in result $bold = '<span class="found">' . $word . '</span>'; $end_result .= '<li>' . str_ireplace($word, $bold, $result) . '</li>'; } echo $end_result; } else { echo '<li>No results found</li>'; } } ?> I tried to fix the code but I'm failed, the error is Fatal Error: Call to undefined method::mysqli_select_list() in ....... line 14 <?php //if we got something through $_POST if (isset($_POST['search'])) { // here you would normally include some database connection include('db_Connect.php'); $db = mysqli_connect($db_Host, $db_User, $db_Pass, $db_Name); // never trust what user wrote! We must ALWAYS sanitize user input $word = mysqli_real_escape_string($db, $_POST['search']); $word = htmlentities($word); // build your search query to the database $sql = "SELECT fname FROM pages WHERE fname LIKE '%" . $word . "%' ORDER BY title LIMIT 10"; // get results $row = $db->select_list($sql); if(count($row)) { $end_result = ''; foreach($row as $r) { $result = $r['title']; // we will use this to bold the search word in result $bold = '<span class="found">' . $word . '</span>'; $end_result .= '<li>' . str_ireplace($word, $bold, $result) . '</li>'; } echo $end_result; } else { echo '<li>No results found</li>'; } } ?> I want to change it to mysqli, but I dont know. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/282185-facebook-like-search-engine/ Share on other sites More sharing options...
Solution fastsol Posted September 16, 2013 Solution Share Posted September 16, 2013 I didn't look through the code but here is a couple tutorial series that if you combine the concepts should get you what you are after. http://www.youtube.com/playlist?list=PLCE5448BCC44A1504 http://www.youtube.com/playlist?list=PL731FE4E4AFF8AD21 Quote Link to comment https://forums.phpfreaks.com/topic/282185-facebook-like-search-engine/#findComment-1449703 Share on other sites More sharing options...
cary1234 Posted September 16, 2013 Author Share Posted September 16, 2013 Thanks fastsol, okay. I will study those. Quote Link to comment https://forums.phpfreaks.com/topic/282185-facebook-like-search-engine/#findComment-1449707 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.