gpt4 book ai didi

php - 将一张表中的两列合并为一个输出

转载 作者:行者123 更新时间:2023-11-29 08:23:33 24 4
gpt4 key购买 nike

我有一个这样的表:

Table

我想将列“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)

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

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

谢谢

最佳答案

这不是您要找的吗?中间有一个空格?

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

或者简单地说:

echo $uitvoeringsid.' '.$uitvoeringoms;

关于php - 将一张表中的两列合并为一个输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18587210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com