Show Needed | v1.1 | etcgfm v1.0.1 | up 5.17.14

  1. 4 years ago
    Edited 4 years ago by Dite

    Required Mods
    get_category, pending

    Purpose
    Here's a code for you to use to list all of the cards you need to complete each deck in a category. It's best used for Keeping sets, if there's an option to take a choice "##" card, and your collecting deck(s) already have it.
    For me, it's not something I keep as a constant reference, but when I need to, I can just plug it in and pick my choice card with it.

    Preview

    Function
    This goes into your func.php, custom function page, or any pages that you will use the function on.

    function show_needed( $tcg, $category, $count,$pend = 0, $low = 0) {
     $total = array();
      if (strtolower($category)==='collecting'){
       	$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'];
    	$worth = intval($count);
    	$result = $database->query("SELECT * FROM `collecting` WHERE `tcg` = '$tcgid' AND `mastered` = '0' AND `worth` = '$worth' ORDER BY `sort`, `deck`");
    	$cards = '';
    	while ( $row = mysql_fetch_assoc($result) ) {$cards .= $row['cards'].', '; $total[$row['deck']] = $row['count'];}
      $cards = substr($cards,0,-2);} else {	$cards = get_category($tcg, $category); }
    	$cards = explode(', ',$cards);
    	$cards = array_unique($cards); array_walk($cards, 'trim_value');
        $deck = array( );
        //Get decks
    	foreach ($cards as $card) {$deck[ ] = substr($card, 0, -2);}
        $group = array_combine($cards,$deck);
        $deck = array_unique($deck);
    	//Results
        foreach ($deck as $check) {
    		if(isset($total[$check])){$all = $total[$check];} else{$all = $count;}
    		$mine = array();
    		$got = array_keys($group, $check);
    		foreach ($got as $num) {$mine[ ] = substr($num, -2); }
    		$def = range(1,$all);
    		$default = array( );
    		foreach($def as $no){if($no < 10){$default[ ] = '0'.$no;} else {$default[ ] = $no;}}
    		$diff = array_diff($default,$mine);
    		foreach($diff as &$might){
    			$pending = pending($tcg, $check.$might);
    			if($pending > 0){
    				if($pend === 1){$might = '<b>'.$might.'</b>';}
    				else{ $might = '';}
    			}
    		}
    		$diff = array_filter($diff, 'strlen');
    		$need = count($diff);
    		if($low === 0 || $need <= $low){
    			$diff = implode('/',$diff);
    			echo $check.': '.$diff.'<br/>';
    		}
    	}
    }

    Execution
    Place this wherever you want the list to go.

    show_needed( $tcg, $category, $count, $pend, $low)

    The required variables to change are $tcg, to whatever TCG you're using it on; $category to whatever category you're using it on, and $count to the number of cards in a deck. So, if they are 20 card decks, you put 20 (it needs it to tell you what you need).
    NOTE: You may use it for collecting decks as well! Just name 'collecting' as your category, and make $count the worth you want to use. It uses each deck's given count.

    The optional variables are $pend and $low.
    $pend is a yes(1) or no (0) decision--do you want to include pending cards? If you choose no (set it to 0, or enter nothing), pending cards will not show up with the other numbers. If you choose yes (set it to 1), the pending cards will show up in bold on the list.

    $low is a filter for how many cards you need. If you set it to 3, it will only show decks that need 3 cards or less. If you set it to 0, it will show all cards.

    Double-use note: $pend INCLUDES pending cards--not just shows them. That means that If you set it to "Yes", they will count as needed cards for $low.
    Ex: You need apple02/04/06, and have apple03 pending.
    $pend = 0, $low = 0 // displays "apple02/04/06"
    $pend = 0, $low = 3 // displays "apple02/04/06"
    $pend = 1, $low = 0 // displays "apple02/03/04/06"
    $pend = 1, $low = 3 // does not display the apple deck.
    $pend = 1, $low = 4 // displays "apple02/03/04/06"

    Upcoming Versions
    Nothing specific. If anyone wants a certain input and/or output, I'll update later versions to include them.

    Previous/Current Versions
    1.1 - Cleaned up the coding a bit, added optional pending card inclusion, cards needed filter, and the ability to show needed cards for collecting decks.
    1.0 - Initial version.

  2. Hi thanks for this :)

    I added it to my site and all i got was

    01/02/03/04/05/06/07/08/09/10/11/12/13/14/15.

    so i think i may have done something wrong, could anyone take a look if they have chance? I have php5.3 but can switch to php5.2

    my page coding @ http://tny.cz/b4d8751e - line 31
    my func.php @ http://tny.cz/ed59a6dc - line 546
    in practice @ http://randomflowers.co.uk/chemistry.php

  3. "Rebekah" Hi thanks for this :)

    I added it to my site and all i got was

    01/02/03/04/05/06/07/08/09/10/11/12/13/14/15.

    so i think i may have done something wrong, could anyone take a look if they have chance? I have php5.3 but can switch to php5.2

    my page coding @ http://tny.cz/b4d8751e - line 31
    my func.php @ http://tny.cz/ed59a6dc - line 546
    in practice @ http://randomflowers.co.uk/chemistry.php

    I'm not sure how much this matters. I'm sure it makes a difference. But you have:

    <?php show_needed(chemistry, collecting, 15); ?>

    Where the first letter in chemistry is lowercase. I'm assuming it should be uppercase seeing as that's how you have it on other lines i.e.:

    <?php echo get_additional('Chemistry','level'); ?>

    That should fix the issue. I don't see anything else wrong other then that.

  4. Hi Nina, thanks for looking i didnt spot that :)

    I've just edited my code, cleared cache and tested on another browser but changing to a capital C hasn't changed anything :(

    Thanks again for looking!

  5. Bloo

    8 Nov 2013 Administrator kablooey.net

    Hmm. Try adding quotes?

    <?php show_needed('Chemistry', 'collecting', 15); ?>
  6. You're welcome and try what Bloo suggested. I didn't even realize you didn't have quotes in the coding. I know that I had that problem as well using s different mod and that's all it needed.

  7. If I remember correctly, the quotes are needed to ensure what the string is (as strings can have commas, so it wouldn't know where to begin and end).
    The fact that it doesn't have any decks or anything means it's probably not grabbing the category (which it probably wouldn't with this error), so that should fix it. If it doesn't, let me know, and I'll make sure I didn't mis-copy something in the code.

  8. Edited to overwrite

    I feel so stupid right now as i have just realised instead of putting the category name in which is 'keepingnext' i inputted in the name i gave the name i orriginally had for the page those decks are on.

    sorry for wasting your time looking at this, I can only assume that as i call each collecting deck up to get my layout as is then this affects those decks showing up or that it's not possible to show these decks.

    Thanks to all of you for looking at this for me, i just can't believe it was a stupid mistake.

    <?php } elseif ($_SERVER['QUERY_STRING'] == "collecting") { ?>
    
    <?php define('VALID_INC', TRUE); include 'func.php';
    include('header.php'); ?>
    
    <p><center><h1>Chemistry</h1> <br><b>  
    <a href="http://randomflowers.co.uk/chemistry.php">Main</a> .. 
    <a href="http://randomflowers.co.uk/chemistry.php?collecting">Collecting</a> ..  <a href="http://randomflowers.co.uk/chemistry.php?future">Future Collecting</a> ..
    <a href="http://randomflowers.co.uk/chemistry.php?keeping">Keeping</a> .. 
    <a href="http://randomflowers.co.uk/chemistry.php?mc">Member Cards</a> .. 
    <a href="http://randomflowers.co.uk/chemistry.php?soulmate">Soulmates</a> .. 
    <a href="http://randomflowers.co.uk/chemistry.php?trading">Trading & Doubles</a> .. 
    <a href="http://randomflowers.co.uk/chemistry.php?pending">Pending</a> .. 
    <a href="http://randomflowers.co.uk/chemistry.php?mastered">Mastered</a> .. </center></b>
    
    <p>
    
    <a name="collecting"><h1>Collecting</a></h1></a>
    <center>
    
    <table>
    <tr>
    <td valign="top"><?php show_collecting('chemistry','','anas-dimitrianya'); ?></td>
    <td valign="top"><?php show_collecting('chemistry','','angel-gunnfred'); ?></td>
    <td valign="top"><?php show_collecting('chemistry','','batb-lumierecogsworth'); ?></td>
    </tr>
    
    <tr>
    <td valign="top"><?php show_collecting('chemistry','','bbt-pennyamy'); ?></td>
    <td valign="top"><?php show_collecting('chemistry','','gg-lukelorelai'); ?></td>
    <td valign="top"><?php show_collecting('chemistry','','ggirl-danserena'); ?></td>
    </tr>
    
    <tr>
    <td valign="top"><?php show_collecting('chemistry','','herc-herculesmeg'); ?></td>
    <td valign="top"><?php show_collecting('chemistry','','poto-phantomchristine'); ?></td>
    <td valign="top"><?php show_collecting('chemistry','','sat-zacklaney'); ?></td>
    </tr>
    
    <tr>
    <td valign="top"><?php show_collecting('chemistry','','woo-dorothytoto'); ?></td>
    <td valign="top"><?php show_collecting('chemistry','','sd-rebekah'); ?></td>
    </tr>
    </table>
    
    </center>
    <?php include('footer.php'); ?>
  9. "Rebekah" I feel so stupid right now as i have just realised instead of putting the category name in which is 'keepingnext' i inputted in the name i gave the name i orriginally had for the page those decks are on.

    sorry for wasting your time looking at this, I can only assume that as i call each collecting deck up to get my layout as is then this affects those decks showing up or that it's not possible to show these decks.

    I might be misunderstanding this, but do you mean the collecting decks not showing up in the show_needed list?
    If so, it's because it pulls a category, and there's no "Collecting" category. The code was made mainly for keeping decks. If you'd like to be able to see which cards you need for your collecting deck without accidentally putting the wrong number, I can tell you how to add the title to the filler cards in your collecting deck (so that when you hover over a filler, it tells you that missing card).

  10. thanks for the help and explanation Dite, i think its me misunderstanding the mod, its fine though i don't need to show those for the collecting decks now :) thanks for spending the time to look at this though.

  11. Just a note to let everyone know I took some time and added everything I planned to, as well as making it usable for Collecting decks.

  12. Maybe I'm missing it, but I can't seem to find the pending function any where. Is it not available anymore? I have the previous version of this mod working, but I can't get this version working because I don't have that function.

  13. @Drakmin Maybe I'm missing it, but I can't seem to find the pending function any where. Is it not available anymore? I have the previous version of this mod working, but I can't get this version working because I don't have that function.

    I've been looking for this as well but can't seem to find it anywhere.

  14. Hi Dite, really looking forward to using this mod but I'm coming up with an error: "Fatal error: Call to undefined function pending() in /home/carbonb/public_html/flashlight/func.php on line 469"

    line 469: $pending = pending($tcg, $check.$might);
    page I'm trying to use it on: link
    code on page: <?php show_needed( 'Small Screen', 'collecting', 20, $pend=0, $low=0); ?>
    and attached is my func.php

    let me know if you need to see any of my other code

  15. It's because this version of the show_needed function requires another function called pending. The pending function is not included in this one. It's completely separate from the show_needed function. A few of us are looking around to find it. If I find it before there's a reply, I'll let you guys know where it is.

  16. Oooooh okay I see, thanks.

  17. Crap. Sorry guys. I've been forgetting to check this.

    And, I didn't realize I didn't have a pending function (sometimes, when I have a function for a while, I use it and don't think about it. XP)
    Add this function before it and see if it works:

    function pending($tcg, $card){
    	$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'];
    	$pending = $database->num_rows("SELECT * FROM `trades` WHERE `tcg`='$tcgid' AND `receiving` LIKE '%$card%'");
    	return $pending;
    }
  18. Okay so I added that snippet, and I'm still getting an error, this time "Fatal error: Call to undefined function get_category() in /home/carbonb/public_html/flashlight/func.php on line 450"
    Attaching my func.php again in case it's needed

  19. That mod is here .
    It's a mod I've started using a lot (it's a function to get the list of cards in a category, so it cuts down on the coding of other mods, especially if I need to grab multiple categories.

  20. Alright so it's working great for my keeping category, but I'm getting ": 01/02/03/05/07/08/09/10/11/12/13/14/15/16/17/18/19/20" for my collecting.

  21. Newer ›

or Sign Up to reply!