Tabinyashi Media

Picking the Winner

The Digital Drawing Systtem is created using MySql database, a payment processor called 'Stripe' and a server-side progaming language called 'php'. When you purchase a news letter package from the Tabinyashi Media website, Stripe generates a 'payment intent' number which is unique to each indivdual purchase. This number is then stored in MySql database as well as the name of the news letter package purchased. Below is screenshot of MySql database. Highlighted in red boxes are the names of:

Below is a copy of the php code we use to fetch data from the MySql database and simulate a random draw.

<?php

// Fetch data from the transactions table

$query = "SELECT txn_id, item_name FROM transactions";

$result = $db->query($query);

// Initialize an array to store entries

$entries = [];

// Calculate entries and populate the entries array

while ($row = $result->fetch_assoc()) {

$txnId = $row['txn_id'];

$itemName = $row['item_name'];

// Determine the number of entries based on item_name

$entriesCount = ($itemName === 'Diamond Package') ? 24 : (($itemName === 'Premium Package') ? 8 : (($itemName === 'Basic Package') ? 1: 0));

// Create entries for the participant

for ( $i = 0; $i < $entriesCount; $i++) {

$entries[] = $txnId;

  }

}

// Perform random selection

$numberOfWinners = 1;

$winners = [];

if (count($entries) > 0) {

shuffle($entries);

$winners = array_slice($entries, 0, $numberOfWinners);

}

// Display winners

foreach ($winners as $winnerTxnId) {

  echo "Winner: $winnerTxnId<br>";

}

?>

Here's a step-by-step explanation of what the code does:

The code simulates a random draw for winners based on the number of entries each participant has, where participants with more entries have a higher chance of winning. Purcahsing multiple news letter packages creates multiple unique payment intent numbers and effectively increases the chances of winning because each unique payment intent number is treated as a separate entry.

The newsletter making your business better

Unit 801/59 O’Connell St, Kangaroo Point QLD 4169 | support@tabinyashimedia.com | Phone: 0488165650

Do you want to gain a competitive edge in the market? Enter your email below to learn Advanced Business Strategy.