0

我有一张这样的桌子:

桌子

我想将列 'uitvoeringid' 和 'uitvoeringoms' 结合起来,并输出为一个,它们之间有空格。

这是我的课:

public function getBanden($id = NULL, $merk = NULL, $seizoen = NULL)
{
    $sql = "SELECT * FROM Uitvoering";
    if(!empty($id)) 
    {
        $sql .= " WHERE uitvoeringid=:id"; 
        if(!empty($merk)) { $sql .= " AND merkcode=:merk"; }
        if(!empty($seizoen)) { $sql .= " AND uitvoeringseizoen=:seizoen"; }
    }
    else if(!empty($merk)) 
    { 
        $sql .= " WHERE merkcode=:merk"; 
        if(!empty($seizoen)) { $sql .= " AND uitvoeringseizoen=:seizoen"; }
        $sql .= " ORDER BY uitvoeringvoertuigtype ASC, uitvoeringoms ASC";
    }

    try
    {
        $stmt = $this->db->prepare($sql);
        if(!empty($id)) { $stmt->bindParam(":id", $id, PDO::PARAM_INT); }
        if(!empty($merk)) { $stmt->bindParam(":merk", $merk, PDO::PARAM_STR); }
        if(!empty($seizoen)) { $stmt->bindParam(":seizoen", $seizoen, PDO::PARAM_STR); }
        $stmt->execute();
        $this->bandenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
        $stmt->closeCursor();

        return $this->bandenlijst;
    }
    catch (Exception $e)
    {
        die ( $e->getMessage() );
    }
}

这是我输出数据的文件的一部分:

if(isset($_POST['band_submit']) && $_POST['band_submit'] == "Zoek" || isset($_GET['merk']) && isset($_GET['type']) && isset($_GET['profiel']))
{
    $merk = NULL;
    $seizoentype = NULL;
    if(isset($_POST['band_submit']) && $_POST['band_submit'] == "Zoek")
    {
        if($_POST['band_seizoen'] != "0") { $seizoentype = $_POST['band_seizoen']; }
        $merk = $_POST['band_merk'];
    }
    else if(isset($_GET['merk']) && isset($_GET['type']))
    {
        if($_GET['type'] != "0") { $seizoentype = $_GET['type']; }
        $merk = $_GET['merk'];
    }
    else { $seizoentype = NULL; $merk = NULL; }
    $strSeizoen = NULL;
    if ($seizoentype == "ZO") { $strSeizoen = "Onze zomerbanden"; }
    elseif ($seizoentype == "WI") { $strSeizoen = "Onze winterbanden"; }
    elseif ($seizoentype == "AS") { $strSeizoen = "Onze All-seasonbanden"; }
    elseif ($seizoentype == "OV") { $strSeizoen = "Onze Overige banden"; }
    else { $strSeizoen = "Alle A-merken en topklasse huismerken"; }
    echo "\t\t\t\t\t<h2>" . $strSeizoen . "</h2>
\t\t\t\t\t<br />\n";

    $merken = $merkclass->getMerken($merk);
    $banden = $bandclass->getBanden(NULL, $merk, $seizoentype);
    $nCount = 0;
    $selband = NULL;
?>
                    <img src="http://www.website.net/logos/<?php echo str_replace(".png", "_150.png", $merken[0]->merk_logo); ?>" width="150" class="logo" alt="<?php echo $merken[0]->merk_naam; ?>"/>
                    <div id="merken">
                        <ul>
<?php
    foreach($banden as $band)
    {
?>
<li><a href="http://example-website.com/<?php   
    echo $band->merkcode;?>/<?php if(isset($seizoentype) && $seizoentype == "ZO") {echo "zomerbanden";}
    else if ($seizoentype == "WI") {echo "winterbanden";}
    else if ($seizoentype == "AS") {echo "all-season-banden";}
    else if ($seizoentype == "OV") {echo "overig";}
    else{ echo "alle-types";}?>/<?php echo $band->uitvoeringid;?>">
    <?php echo str_replace(array(' ', ',', '/', '!'), '-',strtolower($band->uitvoeringoms));?>
    </a>
    </li>
<?php
        if(isset($_GET['profiel']) && $band->uitvoeringid == $_GET['profiel']) { $selband = $band; }
        $nCount++;
    }
    if(empty($selband) && count($banden) > 0)
    {
        $selband = $banden[0];
    }
    else if(count($banden) > 0)
    {
    }
    else
    {
        echo "\t\t\t\t\t\t\t<li>Nothing Found</li>\n";
    }
?>
                        </ul>
                        <div class="clearboth"></div>
                    </div>

我怎样才能设法保持相同的工作,但将“uitvoeringid”和“uitvoeringoms”组合到一个输出中。

所以在这一部分:

<a href="http://example-website.com/<?php   
    echo $band->merkcode;?>/<?php if(isset($seizoentype) && $seizoentype == "ZO") {echo "zomerbanden";}
    else if ($seizoentype == "WI") {echo "winterbanden";}
    else if ($seizoentype == "AS") {echo "all-season-banden";}
    else if ($seizoentype == "OV") {echo "overig";}
    else{ echo "alle-types";}?>/<?php echo $band->uitvoeringid;?>">
    <?php echo str_replace(array(' ', ',', '/', '!'), '-',strtolower($band->uitvoeringoms));?>
    </a>

我希望这条线<?php echo $band->uitvoeringid;?>是“uitvoeringoms”和“uitvoeringid”组合成“test-2341”之类的东西

我试过类似的东西:

$sql = "SELECT concat(uitvoeringid, uitvoeringoms) AS single FROM Uitvoering";

但我仍然想选择一切,而不仅仅是(uitvoeringid,uitvoeringoms)

我有点迷失了试图让它以一种好的方式工作。有人可以帮我吗?:)

对我来说很难以一种好的方式解释这一点,所以我希望你们能理解。

谢谢

4

3 回答 3

2

这不是你要找的吗?中间有空格?

$sql = "SELECT *,concat(uitvoeringid, ' ', uitvoeringoms) AS single FROM Uitvoering";

或者简单地说:

echo $uitvoeringsid.' '.$uitvoeringoms;
于 2013-09-03T08:13:53.517 回答
0

您可以使用相同的语句来获取所有列,但您需要在语句中指定列名,如下所示:

$sql = "SELECT concat(uitvoeringid, ' ' ,uitvoeringoms) AS single, Col_1, Col_2... FROM Uitvoering";
于 2013-09-03T08:18:48.187 回答
0

您可以同时拥有所有数据和组合数据:

$sql = "SELECT *, concat(uitvoeringid, " ", uitvoeringoms) AS single FROM Uitvoering";
于 2013-09-03T08:15:39.580 回答