Update randomly indexed database columns in PHP [closed]
I am pushing a hidden field into the database that will be updated as tickets get bought; this is the field that inserts the column: <input type="hidden" class="other-bookable-tickets-sold" name="_other_tickets[-1][sold]" value="0">
What I have tried:
In the database it creates columns for each field added e.g _other_tickets[0][sold], _other_tickets[1][sold], _other_tickets[2][sold] e.t.c
How do I access and update these random columns?
// update tickets sold
function update_ticket_sold( array $tickets, $listing_id )
{
$other_tickets = get_post_meta( $listing_id, '_other_tickets', true );
if (isset($tickets) && is_array(($tickets))) {
$i = 0;
foreach ($other_tickets as $key => $ticket) {
if (in_array(sanitize_title($ticket['name']), array_column($tickets,'ticket'))) {
$ids = array_keys($ticket);
$column = '_other_tickets[' . $ids . '][sold]';
$already_sold_tickets = (int) get_post_meta($listing_id, $column,true);
$sold_now = $already_sold_tickets + (float) $countable[$i];
update_post_meta($listing_id, $column, $sold_now);
$i++;
}
} //end foreach
}
}
Comments
Post a Comment