php - Sub-queries in a while loop: what is fastest? -
I have to count the number of rows in the table and look for a parameter in a while. Now I am doing it like this but it is very inefficient.
while ($ stmt-> fetch ()) {$ stmt3 = $ mysqli-> Ready ("SELECT COUNT (DISTINCT Id_roster) from sender WHERE id_member =?"); $ Stmt3- & gt; Tie-up ('i', $ id_alerte); $ Stmt3- & gt; Executed (); $ Stmt3- & gt; Store_result (); $ Stmt3- & gt; Bind_result ($ number_dispo); $ Stmt3- & gt; Bring (); Echo $ number_dispo; } Any idea how fast I can make it (without repeating the query in the review of each loop?
You need to combine external query $ stmt with internal query $ stmt3 I have not provided the code for this, so I have tried to display it generally:
SELECT ot. *, R.c.id_roster_count other_table OT Left Join (SELECT id_m Ember, from ID_roster_count as ID (DISTINCT id_roster) from ID dispatch group by ID) as RC OTDID number = RCIMM, where OTER value => <5 code> It may be possible to further optimize it, depending on your other query and table structure.
Comments
Post a Comment