• Resolved yyeric

    (@yyeric)


    I have this below SQL which looks at NextGen Gallery’s wp_ngg_tags table, and do a count. Then it loops through all the rows to bring back the name value.

    I couldn’t get it to do what I wanted, but it does the “count” alright.

    <?php
    
    	global $wpdb;
    	$sql = 'SELECT COUNT(*) FROM wp_ngg_tags ';
    	$count= $wpdb->get_var($sql);
    echo $count;
    echo "<hr>";
    
    for ( $counter = 1; $counter <= $count; ) {
    
    $row = 'SELECT name FROM wp_ngg_tags where id='.$counter;
    
    $name= $wpdb->get_var($row);
    
    echo $name;
    
    $counter=$counter+1;
    
    }
    ?>

    Any help would be appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Why in the world would you do it that way? Most strange way of doing something that I’ve ever seen…

    If you want to loop through all the names, then don’t select them one at a time. That’s pointless and way, way strange.

    $results = $wpdb->get_results('SELECT name FROM wp_ngg_tags');
    foreach ($results as $row) {
    echo $row->name;
    }

    Simple.

    Thread Starter yyeric

    (@yyeric)

    That is just brilliant, I will need to find more doco to work on my SQL for WP.

    Thanks Otto

    Eric

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘SQL doesn’t return values’ is closed to new replies.