• Resolved puffinm

    (@puffinm)


    I have a problem with the “display” function for values from the database. For whatever reason when i use php to call the different values the values that are displayed are repeated each 3 times. I checked and i saw that i have added in total 3 entries inside my database so this could be the reason to why it happened. When i use a template with shortcodes i don’t seem to have the same problem. It only arises when i use php.

    <?php 
    $year1 = '%' . date("Y"). '%';
    $year2 = date("Y");
        $params = array( 
            'where'   => 'publication_date.meta_value LIKE "' . $year1 . '"', 
            'limit'   => -1 // Return all rows 
        ); 
    
        $books = pods( 'publication', $params ); 
    
    while ( $year2 != 2015){
    		  if ( 0 < $books->total() ) { 
    
        $books = pods( 'publication', $params ); 
            while ( $books -> total() ) { 
    
    ?>
    		<once><h2><?php echo $books->display( 'publication_date.name' ); ?></h2></once>
            <p><?php echo $books->display( 'publication_date.name' ); ?>,</p> 
            <p><?php echo $books->display( 'journal_title.name' ); ?>.</p> 
    <?php 
            } 
    }
    --$year2;
    echo $year2;
    $year1 = '%' . $year2 . '%';
        $params = array( 
            'where'   => 'publication_date.meta_value LIKE "' . $year1 . '"', 
            'limit'   => -1 // Return all rows 
        ); 
    
        $books = pods( 'publication', $params ); 
    }
    
    ?>

    This is the code i use but it’s incomplete. I try to dynamically put in place a new year without having to add the year manually by getting inside WordPress. Since the code causes the whole page to crash. I tried to display different values from the database with while($books->total()) and the pods(‘publication’,$params).

    I run a final check and wrote just a random set of words in a template like “a1” if the same problem will arise and it did.

Viewing 1 replies (of 1 total)
  • Plugin Contributor Jim True

    (@jimtrue)

    Well, you’re re-opening the object twice in your code, one within the while loop. That would seem to be an issue:

    
        $books = pods( 'publication', $params ); 
    
    while ( $year2 != 2015){
    		  if ( 0 < $books->total() ) { 
    
        $books = pods( 'publication', $params ); 
            while ( $books -> total() ) { 
    

    You see the problem there?

    You either need to add the year check _into_ your where query or do that validation while the loop is processing, instead of doing two sets of whiles in the same object on the same variable.

Viewing 1 replies (of 1 total)

The topic ‘Problem with data displaying multiple times’ is closed to new replies.