Quarterbore
08-21-2006, 03:29 PM
OK, this code is really not optomized but the MYSQL coding of this is just a little above my own skill. So, I am sharing my vBa module with the hopes that someone can help optomize it as right now I query the database FOUR times in this tiny block!
It works as is but I know someone with more skill then I have would be able to make it work better....
Here are some notes:
I hard coded the two lotteries I use on my site lotteryid = '1' and lotteryid = '2'. I did this as I couldn't figure out how to do this in an array. I also did not program this with phrases as I have no plans to use this in multiple languages.
Here is the code:
<?php
// search for the lottery
$weeklylottery = $vbulletin->db->query_first("SELECT jackpot,enddateline,ticketssold FROM " . TABLE_PREFIX . "vbplaza_lottery WHERE lotteryid = '1' AND active = 1");
// count how many times this user has purchased a ticket for the weekly lottery
$weeklyticketsowned = $vbulletin->db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "vbplaza_lotteryticket
WHERE lotteryid = '1'
AND userid = '" . $vbulletin->userinfo['userid'] . "'
");
$dailylottery = $vbulletin->db->query_first("SELECT jackpot,enddateline,ticketssold FROM " . TABLE_PREFIX . "vbplaza_lottery WHERE lotteryid = '2' AND active = 1");
// count how many times this user has purchased a ticket for the daily lottery
$dailyticketsowned = $vbulletin->db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "vbplaza_lotteryticket
WHERE lotteryid = '2'
AND userid = '" . $vbulletin->userinfo['userid'] . "'
");
$daily['jackpot'] = number_format($dailylottery['jackpot'], $vbulletin->options['vbplaza_decimalplaces']);
$daily['enddate'] = vbdate($vbulletin->options['dateformat'] . ', ' . $vbulletin->options['timeformat'], $dailylottery['enddateline']);
$weekly['jackpot'] = number_format($weeklylottery['jackpot'], $vbulletin->options['vbplaza_decimalplaces']);
$weekly['enddate'] = vbdate($vbulletin->options['dateformat'] . ', ' . $vbulletin->options['timeformat'], $weeklylottery['enddateline']);
echo '<tr><td><div class="smallfont">';
echo 'Daily Lotto: ' . $daily['jackpot'] . '<br />' ;
echo $daily['enddate'] . '<br />';
echo 'You own ' . $dailyticketsowned[count] . ' of the ' . $dailyticketssold . ' tickets.<br /><br />';
echo 'Weekly Lotto: ' . $weekly['jackpot'] . '<br />';
echo $weekly['enddate'] . '<br />';
echo 'You own ' . $weeklyticketsowned[count] . ' of the ' . $weekticketssold . ' tickets.<br />';
echo '</td></tr></div>';
?>
Attached is a screenshot...
Thanks for any help improving this!
It works as is but I know someone with more skill then I have would be able to make it work better....
Here are some notes:
I hard coded the two lotteries I use on my site lotteryid = '1' and lotteryid = '2'. I did this as I couldn't figure out how to do this in an array. I also did not program this with phrases as I have no plans to use this in multiple languages.
Here is the code:
<?php
// search for the lottery
$weeklylottery = $vbulletin->db->query_first("SELECT jackpot,enddateline,ticketssold FROM " . TABLE_PREFIX . "vbplaza_lottery WHERE lotteryid = '1' AND active = 1");
// count how many times this user has purchased a ticket for the weekly lottery
$weeklyticketsowned = $vbulletin->db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "vbplaza_lotteryticket
WHERE lotteryid = '1'
AND userid = '" . $vbulletin->userinfo['userid'] . "'
");
$dailylottery = $vbulletin->db->query_first("SELECT jackpot,enddateline,ticketssold FROM " . TABLE_PREFIX . "vbplaza_lottery WHERE lotteryid = '2' AND active = 1");
// count how many times this user has purchased a ticket for the daily lottery
$dailyticketsowned = $vbulletin->db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "vbplaza_lotteryticket
WHERE lotteryid = '2'
AND userid = '" . $vbulletin->userinfo['userid'] . "'
");
$daily['jackpot'] = number_format($dailylottery['jackpot'], $vbulletin->options['vbplaza_decimalplaces']);
$daily['enddate'] = vbdate($vbulletin->options['dateformat'] . ', ' . $vbulletin->options['timeformat'], $dailylottery['enddateline']);
$weekly['jackpot'] = number_format($weeklylottery['jackpot'], $vbulletin->options['vbplaza_decimalplaces']);
$weekly['enddate'] = vbdate($vbulletin->options['dateformat'] . ', ' . $vbulletin->options['timeformat'], $weeklylottery['enddateline']);
echo '<tr><td><div class="smallfont">';
echo 'Daily Lotto: ' . $daily['jackpot'] . '<br />' ;
echo $daily['enddate'] . '<br />';
echo 'You own ' . $dailyticketsowned[count] . ' of the ' . $dailyticketssold . ' tickets.<br /><br />';
echo 'Weekly Lotto: ' . $weekly['jackpot'] . '<br />';
echo $weekly['enddate'] . '<br />';
echo 'You own ' . $weeklyticketsowned[count] . ' of the ' . $weekticketssold . ' tickets.<br />';
echo '</td></tr></div>';
?>
Attached is a screenshot...
Thanks for any help improving this!