query("SELECT u.*, (SELECT COUNT(*) FROM orders WHERE user_id = u.id) as order_count, (SELECT COALESCE(SUM(total), 0) FROM orders WHERE user_id = u.id AND payment_status = 'completed') as total_spent FROM users u ORDER BY u.created_at DESC")->fetchAll(); ?>
| Customer | Phone | Orders | Total Spent | Joined | Status | |
|---|---|---|---|---|---|---|
|
= strtoupper(substr($c['first_name'], 0, 1) . substr($c['last_name'], 0, 1)) ?>
= htmlspecialchars($c['first_name'] . ' ' . $c['last_name']) ?>
|
= htmlspecialchars($c['email']) ?> | = htmlspecialchars($c['phone'] ?? 'N/A') ?> | = $c['order_count'] ?> | = format_currency($c['total_spent']) ?> | = date('M d, Y', strtotime($c['created_at'])) ?> | = $c['status'] ? 'Active' : 'Inactive' ?> |