Hi, $query = $db->query("SELECT * FROM suburb_tlb WHERE 'suburb' LIKE '$queryString%' OR 'areacode' LIKE '$queryString%' LIMIT 10"); Code (markup): Well I'm implementing an autocomplete function on my new website and I'm having a little bit of trouble with it. What it does it when the user enters a suburb or area code it will search both the suburb and area code tables and return a full suburb and area code. But the code above doesn't seem to work so does anybody know what I'm doing wrong? Thanks a lot Dawilster
Define 'doesn't work'. Nothing at all happens? Something unexpected happens? Wrong results are returned? It causes polio outbreaks in nearby schools? You get an error message somewhere? Give us something more. I would log/capture/find out what your actual SQL statement is that is being used. Maybe you are using the wrong variable names, maybe its inserting invalid characters. Find out what the actual statement is and try to run that through your admin panel and see what gets returned.
plog is right, always elaborate what exactly you are asking. You can also use mysql_error() to identify the mysql error. The problem in the query is single quotes. Do not use single quotes around column names or replace them with back ticks (`). e.g. $query = $db->query("SELECT * FROM suburb_tlb WHERE suburb LIKE '$queryString%' OR areacode LIKE '$queryString%' LIMIT 10"); Code (markup):
Try this: $query = $db->query("SELECT * FROM `suburb_tlb` WHERE (`suburb` LIKE '$queryString%') OR (`areacode` LIKE '$queryString%') LIMIT 10"); Code (markup): make sure to use mysql_real_escape_string() on the $queryString variable.