I’m retrieving all the users from this table and display them into a table (the usernames separated by commas will be displayed each for each table row; each row of exceptions will be displayed as the tables)
cutoff
| user | exceptions |
+-------+------------+
| admin | moderator,john,james,mark,luke,thewbmstr,jane,ben,robert,kumar,ford,bert,peter |
+-------+------------+
| admin | harry,joe |
Get exceptions function
public function get_exceptions($type, $is_arr = false)
{
global $sqlConnection;
$curuser = $this->get_cuname();
$exceptlist = null;
$s = $sqlConnection->prepare("SELECT exceptions FROM cutoff_$type WHERE user = ?");
$s->bind_param('s', $curuser);
$s->execute();
$s->store_result();
$s->bind_result($exceptions);
while ($s->fetch()) {
// Split into arrays
$split .= ';' . $exceptions;
$exceptlist = explode(';', $split);
}
if ($is_arr)
return $exceptlist;
else
return '"' . join('","', $exceptlist) . '"';
}
Load table function
public function load_direct_sales_table($previous = false) {
// the current user/id
$cur_user = $this->get_cuname();
$cur_id = $this->get_cuid();
$exceptlist = $this->get_exceptions('direct', true);
// I don't think if this is correct
foreach ($exceptlist as $excepteach) {
if (!$previous) {
$query = "SELECT user_id, username, first_name, last_name, sale_status, first_sale, name_format";
$query .= " FROM accounts ACC";
$query .= " INNER JOIN info INF ON ACC.user_id = INF.iuid";
$query .= " INNER JOIN sales SAL ON ACC.user_id = SAL.suid";
$query .= " WHERE SAL.mentor = ? AND username NOT IN ($excepteach)";
} else {
$query = "SELECT user_id, username, first_name, last_name, sale_status, first_sale, name_format";
$query .= " FROM accounts ACC";
$query .= " INNER JOIN info INF ON ACC.user_id = INF.iuid";
$query .= " INNER JOIN sales SAL ON ACC.user_id = SAL.suid";
$query .= " WHERE SAL.mentor = ? AND username IN ($excepteach)";
}
$stmt = $GLOBALS['sqlConnection']->prepare($query);
$stmt->bind_param('s', $cur_user);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($user_id, $username, $first_name, $last_name, $sale_status, $first_sale, $name_format);
$total = number_format(self::INCOME * $stmt->num_rows, 2);
$income_currency = self::CURRENCY;
$result = "<table class='income-table'>";
$result .= "<thead>";
$result .= "<tr>";
$result .= "<td>User ID</td>";
$result .= "<td>Full name</td>";
$result .= "<td>Username</td>";
$result .= "<td>Status</td>";
$result .= "<td>Income</td>";
$result .= "</tr>";
$result .= "</thead><tbody>";
while ($stmt->fetch()) {
$qualified = '';
$format_income = number_format(self::INCOME, 2);
$full_name = $this->format_name($first_name, $last_name, $name_format);
if ('QUALIFIED' === $sale_status)
$qualified = 'class="qualified"';
$result .= "<tr>";
$result .= "<td>00{$user_id}</td>";
$result .= "<td>{$full_name}</td>";
$result .= "<td>{$username}</td>";
$result .= "<td {$qualified}>{$sale_status}</td>";
$result .= "<td>{$income_currency}{$format_income}</td>";
$result .= "</tr>";
}
$result .= "</tbody><tfoot>";
$result .= "<td></td>";
$result .= "<td></td>";
$result .= "<td></td>";
$result .= "<td></td>";
$result .= "<td>{$income_currency}{$total}</td>";
$result .= "</tfoot>";
$result .= "</table>";
echo $result;
} else {
$result = "<div class=\"sale-no-result\">";
$result .= "<p>No sales records.</p>";
$result .= "</div>";
echo $result;
}
}
}
I wanted to achieve:
- For each row of exceptions, there will be tables (e.g. 2 rows = 2 tables)
- For each usernames (comma-separated) will be rows of tables (e.g. 5 usernames = 5 rows per table)