CodeIgniter Forums
GROUP_CONCAT question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Regional User Groups (https://forum.codeigniter.com/forumdisplay.php?fid=25)
+--- Thread: GROUP_CONCAT question (/showthread.php?tid=68846)



GROUP_CONCAT question - Germanikus - 09-03-2017

Hello,
I have a question there and I have a problem with the "GROUP_CONCAT".
In my old code, this should merge the Rare names.

That is how it should look
   

This is how it looks without this "GROUP_CONCAT".
   

Let's go with that
   


PHP Code:
<table class="table">
    <
thead>
        <
tr>
            <
th>Nr.</th>
            <
th>Name der Karte (deutsch)</th>
            <
th>Name der Karte (englisch)</th>
            <
th>Rarität</th>
            <
th>Katogorie</th>
        </
tr>
    </
thead>
    <
tbody>
<?
php
    $SQL 
"SELECT
                tb_ygo_karten_kategorie_css,
                tb_edition_stats_nummer,
                tb_ygo_karten_stats_id,
                tb_ygo_karten_stats_name_de,
                tb_ygo_karten_stats_name_en,
                GROUP_CONCAT(db_rare.tb_rare_name SEPARATOR ', ') AS tbrana
            FROM
                db_edition_stats
            LEFT JOIN
                db_rare
                    ON
                        db_rare.tb_rare_id = db_edition_stats.tb_edition_stats_rare
            LEFT JOIN
                db_ygo_karten_stats
                    ON
                        db_ygo_karten_stats.tb_ygo_karten_stats_id = db_edition_stats.tb_edition_stats_karte
            LEFT JOIN
                db_ygo_karten_kategorie
                    ON
                        db_ygo_karten_kategorie.tb_ygo_karten_kategorie_id = db_ygo_karten_stats.tb_ygo_karten_stats_kategorie
            WHERE
                db_edition_stats.tb_edition_stats_edition = "
.$get_edition['tb_edition_id']."
            ORDER BY
                db_edition_stats.tb_edition_stats_nummer"
;
    
$query $this->db->query($SQL);
    foreach (
$query->result() as $karte)
        {
?>
        <tr class="<?php echo $karte->tb_ygo_karten_kategorie_css?>">
            <td><?php echo $karte->tb_edition_stats_nummer?></td>
            <td><a href="<?php echo base_url(); ?>pages/karte/<?php echo $karte->tb_ygo_karten_stats_id?>"><?php echo $karte->tb_ygo_karten_stats_name_de?></a></td>
            <td><a href="<?php echo base_url(); ?>pages/karte/<?php echo $karte->tb_ygo_karten_stats_id?>"><?php echo $karte->tb_ygo_karten_stats_name_en?></a></td>
            <td><?php echo $karte->tbrana?></td>
            <td><?php// echo $pn[$key]['tb_karten_kategorie_name_de'];?></td>
            <td><a href="https://de.yugiohcardmarket.eu/Products/Singles/Code+of+the+Duelist/<?php// echo urlencode($pn[$key]['tb_karten_stats_name_en']);?>"><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span>&nbsp;Cardmarket</button></a></td>
        </tr>
<?php
        
}
?>
    </tbody>
</table> 

PS. If possible answer in German


RE: GROUP_CONCAT question - InsiteFX - 09-04-2017

For one you should not be using database code in your views.

See the CodeIgniter Users Guide HTML Table Class Library.


RE: GROUP_CONCAT question - php_rocs - 09-04-2017

@Germanikus, (SUGGESTION) I always recommend that you run your SQL statement within the Database itself (first). By doing this before you enter it into the code you will know that it works.

I also agree with InsiteFX.