[eTCG] catchmyprefix

Here's a mod you can use to get all cards with a matching prefix from a category.

First step : Install

This goes into your func.php, custom function page, or any pages that you will use the function on.
// Get all cards with a matching prefix from a category.
// $tcg = the name of the TCG as defined in the database; $category = the card category to display; 
// $theprefix = the prefix you're looking for; $thediv = the symbol that separates the prefix from the rest of filename; $doubles = divide pile into uniques + doubles; $notnow = if instead you want to show all the cards that don't have the prefix.

function catchmyprefix($tcg, $category, $theprefix = '', $thediv = '-', $doubles = 0, $notnow = 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");

$theprefix = $sanitize->for_db($theprefix);
$thediv = $sanitize->for_db($thediv);

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);
$thiscard = explode($thediv,$card);
if($notnow > 0){ $willshow = ($theprefix != $thiscard[0]) ? true : false; }
else { $willshow = ($theprefix == $thiscard[0]) ? true : false; }
if($willshow){ echo '<img src="'.$cardsurl.''.$card.'.'.$format.'" alt="" title="'.$card.'" /> '; } }
echo '</p><p class="cards">';
foreach( $cardsdou as $cardd ) {
$cardd = trim($cardd);
$thiscard = explode($thediv,$cardd);
if($notnow > 0){ $willshow = ($theprefix != $thiscard[0]) ? true : false; }
else { $willshow = ($theprefix == $thiscard[0]) ? true : false; }
if($willshow){ echo '<img src="'.$cardsurl.''.$cardd.'.'.$format.'" alt="" title="'.$cardd.'" /> '; } }
echo '</p>';
} else {
echo '<p class="cards">';
foreach( $cards as $card ) {
$card = trim($card);
$thiscard = explode($thediv,$card);
if($notnow > 0){ $willshow = ($theprefix != $thiscard[0]) ? true : false; }
else { $willshow = ($theprefix == $thiscard[0]) ? true : false; }
if($willshow){ echo '<img src="'.$cardsurl.''.$card.'.'.$format.'" alt="" title="'.$card.'" /> '; } }
echo '</p>';
} } }

Second step : Use it

Place this wherever you want the list to go.
catchmyprefix($tcg, $category, $theprefix, $thediv, $doubles, $notnow);
  • Replace $tcg with the TCG you're using it on.
  • Replace $category with the category you want to divide.
  • Replace $theprefix with the value of the prefix you're looking for.
  • Replace $thediv with the symbol that separates the prefix from the rest of filename.
  • Replace $doubles with 1 if you want divide your pile into uniques and doubles (optional).
  • Replace $notnow with 1 if you want show only cards that DON'T have the prefix (optional).

Examples

"I want to show all the cards on my trade pile that start with the photo".
catchmyprefix('TCG name', 'Trade', 'photo');
"Oh. But it uses an '_' after the prefix".
catchmyprefix('TCG name', 'Trade', 'photo', '_');
"Ok. Now I want my doubles in a separate pile too.".
catchmyprefix('TCG name', 'Trade', 'photo', '_', 1);
"Excellent. I only need all my other cards (uniques + doubles) in another pile".
catchmyprefix('TCG name', 'Trade', 'photo', '_', 0, 1);
That's all. If you need help or find some mistake, please let me know :D