I find it hard to understand this ...
I have two tables ... ticket_winners and tickets
in the ticket_winners table , user / profile information ...
Ticket table - this is all the tickets that these users have for one user ID, in each table there can be 10+ tickets for each user.
Question: How can I scroll the second iteration of data when the bits of the table have more than 1 row for each user
function pullTickets() {
$sql = $this->mysql->retrieve("SELECT * FROM ticket_winners ORDER BY id DESC LIMIT 5");
$sql2 = $this->mysql->retrieve("SELECT id, userId, ticketId FROM tickets ORDER BY id ASC LIMIT 5");
while($row = mysql_fetch_array($sql)) {
$results[$row['id']]['user'] = $row['userId'];
while($row2 = mysql_fetch_array($sql2)) {
if($results[$row['id']]['user'] == $row2['userId']) {
$results[$row['id']]['tickets'][$row2['id']] = $row2['ticketId'];
} else {
}
}
}
return $results;
}
PHP Page Example : Works Great
$data = $obj->pullTickets();
foreach($data as $user) {
echo $user['username'];
foreach($data['ticket'] as $ticket) {
echo $ticket['ticketId'];
}
}
What the array looks like:
[1] => Array
(
[batch] => 1
[userId] => 200
[userName] => Craig
[tickets] => Array
(
[1] => GH7JNm72hN
[2] => JudM3rT3is
[3] => KiLPoXCmDF
)
)
[2] => Array
(
[batch] => 1
[userId] => 100
[userName] => Hewbie
needs to continue looping
)
the ticket table does not loop through each user, as in the array [1]. It skips all tickets of other users.