A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

# Tag Info

1

You can select multiple counts from the table based on a condition using a CASE WHEN statement, and when writing SQL or something where formatting helps readability it's normally a good idea to use heredoc. $getSQL = <<<SQL SELECT COUNT(DISTINCT guid) AS allNum, COUNT(DISTINCT CASE WHEN chk='Y' THEN guid END) AS openNum FROM {$table} ...

3

I think there's three big things you might be able to do to improve the performance of this. Write your query such that it doesn't need to execute the subquery for each line and/or have a HAVING clause by using an inner join which will automatically exclude those with no match. Use ST_Distance_Sphere(POINT(:longitude, :latitude), POINT(cities.longitude, ...

2

This monster of a function is hard to use and hard to maintain. Besides, it is bloated with duplicated and/or unnecessary code. Last but not least, the way require "dbconn.script.php"; is called will make your code run slower and make some features (such as transactions) unavailable. Too many connections Your current code is connecting to the database ...

3

Array combine takes Keys + Values as values and combines them. Make sure they are the same size. $result = array_combine( array_column($array, 'level_id'), array_column($array, 'level') ); And also a nice trick with array_map() and NOT using a callback.$test1 = [ 'first-1', 'first-2', 'first-3', 'first-4', ]; \$test2 = [ '...

Top 50 recent answers are included