liamloveslearning Posted September 13, 2010 Share Posted September 13, 2010 Hi all, Experimenting with this instant search buzz only I cant seem to replicate the function! I think my PHP may be cocking up but Ive been staring for too long to see anything. Could anybody take a quick glance and see if they can see anything? <?php if(!empty($_GET['q'])) { search(); } function search() { $con = mysql_connect('localhost','login', 'pass'); mysql_select_db('db', $con); $q = htmlspecialchars($_GET['q'],ENT_QUOTES); $sql = mysql_query(" SELECT post_title as post FROM wp_posts WHERE post_title LIKE '%{$q}%' OR post_title LIKE '%{$q}%' "); $results=array(); while($v = mysql_fetch_object($sql)){ $results[] = array( 'title'=>$v->title, 'post'=>$v->post ); } echo json_encode($results); } ?> Link to comment https://forums.phpfreaks.com/topic/213334-instant-search-nightmare/ Share on other sites More sharing options...
schilly Posted September 13, 2010 Share Posted September 13, 2010 Looks fine. I would sanitize the query string though. Are you getting any errors? Did you output your sql statement to see if it's correct? Link to comment https://forums.phpfreaks.com/topic/213334-instant-search-nightmare/#findComment-1110766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.