0) AS tickets FROM projects WHERE project_client_id = $client_id AND project_archived_at IS NULL ORDER BY project_id DESC"); while ($co_project = mysqli_fetch_assoc($co_sql)) { $co_projects[] = $co_project; } $co_templates = []; $co_pick = ''; $co_sql = mysqli_query($mysqli, "SELECT project_template_id, project_template_name, (SELECT COUNT(*) FROM project_template_ticket_templates WHERE project_template_ticket_templates.project_template_id = project_templates.project_template_id) AS tickets FROM project_templates WHERE project_template_archived_at IS NULL ORDER BY project_template_name ASC"); while ($co_template = mysqli_fetch_assoc($co_sql)) { $co_id = intval($co_template['project_template_id']); $co_templates[$co_id] = $co_template['project_template_name'] . ' - ' . intval($co_template['tickets']) . ' ticket' . (intval($co_template['tickets']) === 1 ? '' : 's'); // One about onboarding is the likely one if ($co_pick === '' && stripos($co_template['project_template_name'], 'onboard') !== false) { $co_pick = (string) $co_id; } } $co_agents = []; $co_sql = mysqli_query($mysqli, "SELECT user_id, user_name FROM users WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL ORDER BY user_name ASC"); while ($co_agent = mysqli_fetch_assoc($co_sql)) { $co_agents[intval($co_agent['user_id'])] = $co_agent['user_name']; } $co_contacts = []; $co_contact_pick = '0'; $co_sql = mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_primary FROM contacts WHERE contact_client_id = $client_id AND contact_archived_at IS NULL ORDER BY contact_primary DESC, contact_name ASC"); while ($co_contact = mysqli_fetch_assoc($co_sql)) { $co_contacts[intval($co_contact['contact_id'])] = $co_contact['contact_name']; if (intval($co_contact['contact_primary']) && $co_contact_pick === '0') { $co_contact_pick = (string) $co_contact['contact_id']; } } ?>