[eTCG] sortmypile

Here's a mod you can use to divide your trade pile (or whatever other section) into different pages without the need to create new categories.

First step : Install

This goes into your func.php, custom function page, or any pages that you will use the function on.
// Divide a card pile into multiple ones without creating new categories.
// $tcg = the name of the TCG as defined in the database; $category = the card category to display; 
// $start = the value you want to start with; $end = the value you want to end with; $doubles = divide pile into uniques + doubles

function sortmypile($tcg, $category, $start = '', $end = '', $doubles = 0) {
$database = new Database;
$sanitize = new Sanitize;
$tcg = $sanitize->for_db($tcg);

$tcginfo = $database->get_assoc("SELECT * FROM `tcgs` WHERE `name`='$tcg' LIMIT 1");
$tcgid = $tcginfo['id'];
$cardsurl = $tcginfo['cardsurl'];
$format = $tcginfo['format'];

$category = $sanitize->for_db($category);
$cards = $database->get_assoc("SELECT `cards`, `format` FROM `cards` WHERE `tcg`='$tcgid' AND `category`='$category' LIMIT 1");

$start = $sanitize->for_db($start);
$start = strtoupper($start);
$end = $sanitize->for_db($end);
$end = strtoupper($end);
$searchme = '/['.$start.'-'.$end.']/i';

if($cards === '') { echo '<p class="cards"><em>There are currently no cards under this category.</em></p>'; } else {
$cards = explode(',',$cards['cards']);
$cards = array_map(trim, $cards);
$array_count = count($cards);	
if($doubles > 0) {
$cardsuni = array_unique($cards);
$cardsdou = array_diff_assoc($cards, array_unique($cards));
echo '<p class="cards">';
foreach( $cardsuni as $card ) {
$card = trim($card);
if(preg_match("$searchme", $card[0])){ echo '<img src="'.$cardsurl.''.$card.'.'.$format.'" alt="" title="'.$card.'" /> '; } }
echo '</p><p class="cards">';
foreach( $cardsdou as $cardd ) {
$cardd = trim($cardd);
if(preg_match($searchme, $cardd[0])){ echo '<img src="'.$cardsurl.''.$cardd.'.'.$format.'" alt="" title="'.$cardd.'" /> '; } }
echo '</p>';
} else {
echo '<p class="cards">';
foreach( $cards as $card ) {
$card = trim($card);
if(preg_match($searchme, $card[0])){ echo '<img src="'.$cardsurl.''.$card.'.'.$format.'" alt="" title="'.$card.'" /> '; } }
echo '</p>';
} } }

Second step : Use it

Place this wherever you want the list to go.
sortmypile($tcg, $category, $start, $end, $doubles);
  • Replace $tcg with the TCG you're using it on.
  • Replace $category with the category you want to divide.
  • Replace $start with the value you want your pile to start with.
  • Replace $end with the value you want your pile to end with.
  • Replace $doubles with 1 if you want divide your pile into uniques and doubles (optional).

Examples

"I want to show all the cards on my trade pile that start with numbers".
sortmypile('TCG name', 'Trade', 0, 9);
"I want to show all the cards on my trade pile that start with letters. And I want my doubles on a separate pile".
sortmypile('TCG name', 'Trade', 'a', 'z', 1);
"I want to show all the cards on my trade pile into two pages: #-M and N-Z".
sortmypile('TCG name', 'Trade', 0, 'm');
echo '<hr />'; /// just to separate the piles
sortmypile('TCG name', 'Trade', 'n', 'z');
"I want to show all the cards on my trade pile that start with A. And I want my doubles on a separate pile".
sortmypile('TCG name', 'Trade', 'a', 'a', 1);
That's all. If you need help or find some mistake, please let me know :D