Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get a single result from a basic PHP function

Here is a PHP function :

public static function getMap($maps, $class = '')
    {
        global $wpdb;
        
        $html = '<div class="jsDivCenter">';
        if(count($maps)){
            
            foreach ($maps as $key => $value) {
                
                if($value[0] !== '' || $value[1] !== ''){
                    
                $sql = "SELECT id FROM {$wpdb->joomsport_maps} WHERE id=".intval($key);
                if($wpdb->get_var($sql)){
                    if(JoomsportSettings::get('partdisplay_awayfirst',0) == 1){
                        $home_map = $value[1];
                        $away_map = $value[0];
                    }else{
                        $home_map = $value[0];
                        $away_map = $value[1];
                    }
                    $html .= '<div class="jsScoreDivMap '.$class.'">'.$home_map.JSCONF_SCORE_SEPARATOR.$away_map.'</div>';
            
                }
                }
            }
        }
        

        $html .= '</div>';

        return $html;

Here is the PHP code :

<?php
        
        if ($rows->lists['maps'] && count($rows->lists['maps'])) {
            echo "<center><font color='blue'>Maps</font></center>";
            echo jsHelper::getMap($rows->lists['maps']);
        }
        ?>

I would like this PHP code to display only the "map" with ID = 4 and not the entire list. How to do this ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks.

>Solution :

try this code:

<?php
        
        if ($rows->lists['maps'] && count($rows->lists['maps'])) {
            echo "<center><font color='blue'>Maps</font></center>";
            $maparray = $rows->lists['maps'];

            if (!empty($maparray[4])){
                 $newmap[4] = $maparray[4];
                 echo jsHelper::getMap($newmap);
                }
        }
        ?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading