Addis Posted April 5, 2014 Share Posted April 5, 2014 I have this function for a search engine using pdo public function GetPageurlByPagecontent() { $db = Database::getDB(); $query = "SELECT * FROM searchengine where pageurl Like Pagecontent"; $searchengine =$db->query($query); return $searchengine; } in the data base pagecontent = keyword pageurl is the url to match that keyword this is my form , I want the pagecontent to match the pageurl only when i do a search by the pagecontent dont even think this query work any ideas? <form action="searchhome.php" method="post" id="search"> <b>Enter Search Term:</b> <input type="text" name="term" size="50"> <b>Results:</b> <select name="results"> <option>10</option> <option>20</option> <option>50</option> </select><br> <input type="submit" value="Search"> </form> <br /> <br /> <?php if(isset($_POST['pageurl'])){ $c_name = $_POST['pageurl']; $pdb2 = new SearchDB(); $search= $pdb2->GetPageurlByPagecontent($c_name); ?> <h1> Results <?php echo $c_name ?> </h1> <?php foreach($search as $list): ?> <br /> <br /> <table> <tr> <td> <p><em> url </em>: <?php echo $list['pageurl'] ?> </p> </td> </tr> </table> <?php endforeach; ?> <?php }?> Quote Link to comment https://forums.phpfreaks.com/topic/287545-search-engine-pdo/ Share on other sites More sharing options...
Solution QuickOldCar Posted April 6, 2014 Solution Share Posted April 6, 2014 You need to pass the $_POST value to your function and then to your query public function GetPageurlByPagecontent($term) { $db = Database::getDB(); $query = "SELECT * FROM searchengine where pageurl Like '$term'"; $searchengine =$db->query($query); return $searchengine; } if(isset($_POST['term']) && trim($_POST['term']) != ''){ $term = trim($_POST['term']); } else { $term = "something"; } Is there more code to it than this?, surely it wouldn't make a query as is. Is the dropdown select supposed to be a limit on how many results to display? If so also pass that value into the function and query and add LIMIT https://dev.mysql.com/doc/refman/5.7/en/select.html [LIMIT {[offset,] row_count | row_count OFFSET offset}] There is a pagination tutorial here at phpfreaks that would be much better to use. http://www.phpfreaks.com/tutorial/basic-pagination In my opinion you should get pagination working first and can insert search terms into it Instead of LIKE, you can do a fulltext search which would bring better results and simplify multiple keyword terms https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Quote Link to comment https://forums.phpfreaks.com/topic/287545-search-engine-pdo/#findComment-1475091 Share on other sites More sharing options...
Addis Posted April 7, 2014 Author Share Posted April 7, 2014 It worked using the simple search and i had to edit the sql statement a bit as for the pagination and full text will modify it at a later date.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/287545-search-engine-pdo/#findComment-1475188 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.