Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The question is not very clear but trying to answer it. I am not giving you a complete fix since that wouldn't develop the developers capacity at all.</p> <p>Your code is very vulnerable to SQL injection, that's a first thing to take a look at. The $q is dangerous in this case. Also you don't check whether your query succeeded or not.</p> <pre><code>echo "$cname|$\n"; </code></pre> <p>This is some strange code for me, what is the suggested output? Something like:</p> <pre><code>New York|1 </code></pre> <p>Or do you need another result? This might be ok but my feeling says the other way around: 1|New York is more logical.</p> <p>The suggested SQL:</p> <pre><code>select city from location where city LIKE '%$q%' LIMIT 1 </code></pre> <p>Will leave you with a maximum of 1 result while you seem to want multiple results but every city only once, is that correct?</p> <p>In file: CityAutoComp.php why do you need ob_start() and why is there that table row code? That file should do no more than outputting the results it finds directly. Keep that very simple.</p> <p>About your speed issue you should use some debugger in for example a browser to see where the delay happens. Next to that testing with: microtime() might give you concrete locations of the delays: <a href="http://php.net/manual/en/function.microtime.php" rel="nofollow">http://php.net/manual/en/function.microtime.php</a></p> <p>For example put it around the query and see whether that's really the issue.</p> <p>In general caching might be good for these results but it really depends on your case, it might turn out that caching isn't needed at all or all results should be realtime. That's when caching might turn out to be very expensive. So first measure before adding more complexity.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload