Jump to content

Instant Search Nightmare


liamloveslearning

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.