I have an array filled with the result of a query which is as follows:
$ticket[] = array(
'ticket_id' => $row->ticket_id,
'user_id' => $row->user_id,
'raffle_ticket_num' => $row->raffle_ticket_num
);
Now, in a while loop, I check in all arrays inside $tickets if my variable $number equals 'raffle_ticket_num'. I do this with the following code (from @Fuzzy Tree):
$ticket_num=1;
while ($ticket_num <= $total_slots){
foreach($ticket as $test) {
if($test['raffle_ticket_num'] == $ticket_num) {
echo $ticket_num.' claimed by '.$test['user_id'];
}
else{
echo $ticket_num;
}
}
$ticket_num++;
}
The problem that I'm having now is that because I'm using a foreach loop, if more than one results are found, it causes it to echo each result as much as there are rows in $ticket[]... So with 2 rows it echos everything 2 times (because of the foreach). Does anyone know a solution or alternatives for this?
You can see it live here: http://tinyurl.com/hxbhx7y .The bold numbers are slot 21 and 38 which are taken and showing the user_id (1). But as you can see it shows each number 2 times (because foreach has 2 results)
EDIT: Post updated with @Fuzzy Tree's answer
foreachlike the one below, should suffice