Skip to Main Content
Ten (
adurotum
) wrote
in
colors_trade
2014-01-16 03:30 am (UTC)
no subject
... that is really weird, it looks pretty much identical to what I have.
Just in case something got messed up in the code, here's my code for that function (I haven't done any alterations to it).
// Generate a total card count/worth of all cards in the collection, or by category. $tcg = the name of the TCG as defined in the database; $type = worth OR empty to ignore worth; $cat = 'CATEGORY NAME' OR 'collecting' OR 'mastered' OR 'pending' OR empty to count all cards in collection function cardcount ($tcg,$type = '',$cat = '') { $database = new Database; $tcginfo = $database->get_assoc("SELECT * FROM `tcgs` WHERE `name`='$tcg' LIMIT 1"); $tcgid = $tcginfo['id']; // Count categories $result = $database->query("SELECT `category`,`cards`,`worth` FROM `cards` WHERE `tcg`='$tcgid'"); while ( $row = mysql_fetch_assoc($result) ) { $categories[] = $row['category']; if ( $row['cards'] === '' ) { $$row['category'] = 0; } else { $cards = explode(',',$row['cards']); $$row['category'] = count($cards); } if ( $type === 'worth' ) { $$row['category'] = $$row['category'] * $row['worth']; } $total = $total + $$row['category']; } // Count collecting $result = $database->query("SELECT `cards`,`worth` FROM `collecting` WHERE `tcg`='$tcgid' AND `mastered`='0'"); while ( $row = mysql_fetch_assoc($result) ) { if ( $row['cards'] !== '' ) { $cards = explode(',',$row['cards']); if ( $type === 'worth' ) { $collecting = $collecting + count($cards) * $row['worth']; } else { $collecting = $collecting + count($cards); } } } $total = $total + $collecting; // Count mastered $result = $database->query("SELECT `cards`,`worth` FROM `collecting` WHERE `tcg`='$tcgid' AND `mastered`='1'"); while ( $row = mysql_fetch_assoc($result) ) { if ( $row['cards'] !== '' ) { $cards = explode(',',$row['cards']); if ( $type === 'worth' ) { $mastered = $mastered + count($cards) * $row['worth']; } else { $mastered = $mastered + count($cards); } } } $total = $total + $mastered; // Count pending $result = $database->query("SELECT `giving`,`givingcat` FROM `trades` WHERE `tcg`='$tcgid'"); while ( $row = mysql_fetch_assoc($result) ) { if ( $row['giving'] !== '' ) { $cardgroups = explode(';',$row['giving']); $cardcats = explode(',',$row['givingcat']); array_walk($cardcats, 'trim_value'); $i = 0; foreach ( $cardgroups as $group ) { $group = explode(',',$group); array_walk($group, 'trim_value'); if ( $cardcats[$i] === 'collecting' ) { $exists = $database->num_rows("SELECT `worth` FROM `collecting` WHERE `tcg`='$tcgid' AND `mastered`='0' AND `deck` LIKE '%".$group[0]."%'"); if ( $exists > 0 ) { $groupworth = $database->get_assoc("SELECT `worth` FROM `collecting` WHERE `tcg`='$tcgid' AND `mastered`='0' AND `deck` LIKE '%".$group[0]."%' LIMIT 1"); if ( $type === 'worth' ) { $pending = $pending + count($group) * $groupworth['worth']; } else { $pending = $pending + count($group); } } else { $pending = $pending + count($group); } } else { $groupworth = $database->get_assoc("SELECT `worth` FROM `cards` WHERE `tcg`='$tcgid' AND `category`='".$cardcats[$i]."'"); if ( $type === 'worth' ) { $pending = $pending + count($group) * $groupworth['worth']; } else { $pending = $pending + count($group); } } $i++; } } } $total = $total + $pending; if ( $cat === '' ) { return $total; } else { return $$cat; } }
(
104 comments
)
Post a comment in response:
From:
Anonymous
This account has disabled anonymous posting.
OpenID
Identity URL:
Log in?
Dreamwidth account
Account name
Password
Log in?
If you don't have an account you can
create one now
.
Subject
HTML doesn't work in the subject.
Formatting type
Casual HTML
Markdown
Raw HTML
Rich Text Editor
Message
Log in
Account name:
Password:
Remember me
Other options:
Forget your password?
Log in with OpenID?
Close
menu
Log in
Create
Create Account
Display Preferences
Explore
Interests
Directory Search
Site and Journal Search
Latest Things
Random Journal
Random Community
FAQ
Shop
Buy Dreamwidth Services
Gift a Random User
DW Merchandise
Interest
Region
Site and Account
FAQ
Email
no subject
Just in case something got messed up in the code, here's my code for that function (I haven't done any alterations to it).