Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php GROUPBY在MySQL中不使用换行符?_Php_Mysql - Fatal编程技术网

Php GROUPBY在MySQL中不使用换行符?

Php GROUPBY在MySQL中不使用换行符?,php,mysql,Php,Mysql,我试图将我的数据与国家和年份一起分组,并将其显示在表格中,但目前仅按年份分组,而不是按国家分组。 如下- 美国2020 |Reise | Land | Reisedatnum | Dauer | Reise| | ------- | ------ | ------------- | ------- | ------- | |12324 Ak 23-10-22 AF密集型| 美国2020 |Reise | Land | Reisedatnum | Dauer | Reise| |-|-|-|-|-

我试图将我的数据与国家和年份一起分组,并将其显示在表格中,但目前仅按年份分组,而不是按国家分组。 如下-

美国2020 |Reise | Land | Reisedatnum | Dauer | Reise| | ------- | ------ | ------------- | ------- | ------- | |12324 Ak 23-10-22 AF密集型|

美国2020 |Reise | Land | Reisedatnum | Dauer | Reise| |-|-|-|-|-| |12323 | AG | 3-10-22 | AF |密集型|

但是,由于国家和年份相同,只能在一个表中显示,,目前显示在另一个表中。我还按
keyregion

在数据库中

keyregion = countryname
Year =  $count=$row->jahr;
MySQL查询

    function starttable($year,$country)
    {
 ;
    
        ?>
    <table class="termine" >

        <caption class="date"><b><?php   echo $country;?>&nbsp;<?php echo $year; ?> </b></caption>
        <thead>
        <tr>
            <th scope="col" class="reisenr">Reise Nr.</th>
            <th scope="col" class="land">Land</th>
            <th scope="col" class="datum">Reisedatum</th>
            <th scope="col" class="dauer">Dauer</th>
            <th scope="col" class="reise">Reise</th>
            <th scope="col" class="preis">Reisepreis</th>

        </tr>
        </thead>

        <tbody>
        <?
    }

    function closetable()
    {
        echo "
        </tbody>

    </table>
";
    }

    function ausgabe_einfach($zeile)
    {
        global $status;
        $anfang = htmlentities($zeile->beginn_f,ENT_COMPAT,'UTF-8',0);
        $ende   = htmlentities($zeile->ende_f  ,ENT_COMPAT,'UTF-8',0);
        $commen = ($zeile->comment_de) ? "<div class=\"comment\">". nl2br(htmlentities($zeile->comment_de,ENT_COMPAT,'UTF-8',0)) ."</div>" : "";

        ?>
        <tr>
            <td><?php echo $zeile->reisenr ?></td>

            <td><?php echo $zeile->keycountry .'<a href="http://'. $zeile->Shortlink .'">'.'<br>' .  $zeile->Shortlink . '</a>'?></td>
            <td class="commdate"><?php echo $anfang ?> &ndash; <?php echo $ende ?></td>
            <td><?php echo $zeile->tage+1 ?>&nbsp;T</td>
            <td><?php echo $zeile->tourname ?></td>
            <td><?php echo ($zeile->price) ? $zeile->price."&nbsp;Euro" : "-" ?> </td>

        </tr>
        <?
    }


    // Datenbankverbindung
    $connection = @mysqli_connect("localhost","username","password","DB");
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    if ($connection)
    {
        mysqli_set_charset($connection, "UTF8");
        mysqli_query($connection, "SET lc_time_names = 'de_DE'");

        $keywords = "Afrika";
        $zeig = 1;
        if ($keysuffix == "")
            $where = "WHERE keyregion LIKE \"".$keywords."\" AND zeig='$zeig'" ;
        else
            $where = "WHERE ( keyregion LIKE \"".$keywords."\" OR keycountry LIKE \"".$keywords.$keysuffix."\" )";

        $abfrage =  "SELECT reisenr,beginn,ende,airline,status,price,keywords,keyregion,Shortlink,keycountry,tourname, YEAR(beginn) AS jahr, MONTH(beginn) AS month, DATE_FORMAT(beginn,\"%a, %e.&nbsp;%b\") AS beginn_f,DATE_FORMAT(ende,\"%a, %e.&nbsp;%b %Y\") AS ende_f,comment_de, DATEDIFF(ende,beginn) as tage FROM $tabelle $where ORDER BY jahr, keyregion";

        $ergebnis = mysqli_query($connection, $abfrage);

        $opentab = false;        // Tabelle offen
        $p_month=0;
// Aktueller Jahresdurchlauf

        while($row = mysqli_fetch_object($ergebnis))
        {
            if ($row->month != $p_month)
            {
                $p_month=$row->month;
                $datee= htmlentities($row->beginn,ENT_COMPAT,'UTF-8',0);
                $count=$row->jahr;
                $country= $row->keyregion;
                $bigin =htmlentities($row->beginn,ENT_COMPAT,'UTF-8',0);

                if ($opentab)
                    closetable();
                starttable($count,$country);
                $opentab = true;
            }

            ausgabe_einfach($row);
        }
        if ($opentab)
            closetable();
    }
    else
    { ?>
        Daten können nicht geladen werden.
        <?
    } 
功能启动表($year,$country)
{
;
?>
赖斯。
土地
赖斯达姆
达斡尔族
赖斯
赖斯佩雷斯
&恩达什;
T
Daten können nicht geladen werden。

您能以实际的表格格式而不是自由流文本包含表数据吗?@TimBiegeleisen我已更新了代码。让我们再试一次:请参阅警告:您完全可以使用参数化的预处理语句,而不是手动生成查询。它们由或提供。永远不要相信任何类型的输入!即使您的查询仅由受信任的用户执行。