I have a table called mainevents, and a table called subevents. For each mainevent there are 3 subevents that I want, which match subname='$sub_name' and eventid. When there are a lot of mainevents, the script is too slow. Dragging slow, 10 seconds to load. When I disable subevents loop, the script loads instantly. I think there might be a shorter/faster/easier way of writing the following. Maybe all in one query. I'm not completely sure.
$a=sqlsrv_query($conn, "SELECT
    eventid,status,name, CONVERT(varchar(100),date,107) AS dt 
    FROM dbo.mainevents WHERE 
    ( date >= '$start_date' AND date <= '$stop_date' ) AND disabled='0'
    ORDER BY category asc");
while($e=sqlsrv_fetch_array($a)){
    $b=sqlsrv_query($conn, "SELECT 
        subid, subname FROM dbo.subevents WHERE
        eventid='$e[eventid]' AND subname='$sub_name' ORDER BY subname");
    while($s=sqlsrv_fetch_array($b)){
        //do stuff
    }
}
 
    