我有一个脚本正在阅读我的车轮品牌。如果我选择一个轮子,它会显示该品牌的所有轮子...
但是因为我做了 GROUP BY merk_naam 所以在我的下拉列表中不会有 100 个相同的品牌,我不能全部展示它们......
有人可以帮我解决以下问题:
我现在有两张桌子:
表 1:it_merken
表 2:it_merken2
我想要下拉列表中的merk_naam
但是当我这样做时,在这个例子中我得到了很多像 AS 2 一样的双倍......
我想在一个查询中加入表 1 和表 2 的 merk_naam ......
我想不通怎么...
有人可以帮帮我吗?
这是我现在使用 GROUP BY 上的课程:
<?php
class merken extends connect
{
/**
* Merken lijst
*
* @param object
*/
private $merkenlijst;
/**
* Vraag merken op uit database
*
* @param int $id
* @return array
*/
public function getMerken($database, $id = NULL)
{
$sql = "SELECT merk_code, merk_logo, merk_naam, wiel_foto, wiel_nummer, wiel_info FROM ".$database."_merken";
if(!empty($id))
{
$sql .= " WHERE merk_code=:id";
}
else
{
$sql .= " GROUP BY merk_naam";
}
try
{
$stmt = $this->db->prepare($sql);
if(!empty($id)){ $stmt->bindParam(":id", $id, PDO::PARAM_STR); }
$stmt->execute();
$this->merkenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
$stmt->closeCursor();
return $this->merkenlijst;
}
catch (Exception $e)
{
die ( $e->getMessage() );
}
}
/**
* Maak een database object en sla de data op
*
* @param object $dbo
* @return void
*/
public function __construct($dbo = NULL)
{
/*
* Roep de parent constructor aan om te controleren op
* een database object
*/
parent::__construct($dbo);
}
}
?>
这在我的下拉列表中给了我每个品牌一次,但是当我什么都不选择时,我想显示所有品牌,因为我现在使用 GROUP BY,所以在提交后我只能看到每个品牌一个轮子。
这是我的 PHP 和 HTML:
<div class="bandwielkolom">
<form name="wielenzoeken" action="index.php?lang=<?php echo $lang; ?>&p=<?php echo $_GET['p']; ?>#keuze" method="post">
<table class="wielentabel">
<tr>
<th colspan="2"><?php echo $searchwheelsbybrand; ?><a name="wiel"></a></th>
</tr>
<tr>
<td><?php echo $brand; ?>:</td>
<td>
<select name="wiel_merk" onchange="enable()">
<option value="0">- <?php echo $brand; ?> -</option>
<?php
$merken = $merkclass->getMerken($website, $merk);
foreach($merken as $merk)
{
echo "\t\t\t\t\t\t\t\t\t\t\t<option value=\"".$merk->merk_code."\"";
if(isset($_GET['search']) && $_GET['search'] == "wiel" && isset($_GET['merk']) && $_GET['merk'] != "0" || isset($_POST['wiel_submit']) && $_POST['wiel_merk'] != "0") { echo " selected=\"selected\""; }
echo ">".$merk->merk_naam."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="wiel_submit" value="<?php echo $search; ?>"/></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</form>
</div>
</div>
<div class="clearboth"></div>
<div id="main-right">
<?php
foreach($teksten as $tekst)
{
?>
<h1><strong><?php echo $tekst->tekst_header; ?></strong></h1>
<?php echo $tekst->tekst_content."\n"; ?>
<?php
if(!empty($tekst->tekst_img))
{
?>
<div class="imgcontainer">
<div class="imgcontent">
<img src="<?php echo $tekst->tekst_img; ?>" class="content_image" alt="<?php echo $tekst->tekst_header; ?>" />
</div>
</div>
<?php
}
?>
<?php
}
?>
</div>
</div>
<div class="clearboth"></div>
<div id="main-left">
<ul class="wheels">
<?php
if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == $search || isset($_GET['merk']))
{
$merk = NULL;
if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == $search)
{
echo "\t\t\t\t\t<h2>".$brandselection."</h2>
\t\t\t\t\t<br />\n";
$merk = $_POST['wiel_merk'];
}
?>
<?php
$merken = $merkclass->getMerken($website, $merk);
foreach($merken as $merk)
{
?>
<li><span class="title"><?php echo $merk->wiel_info; ?></span>
<a href="http://www.website.nl/website/images/w3/<?php echo $merk->wiel_foto; ?>" class="preview" title="Fotonummer: <?php echo $merk->wiel_foto; ?>">
<img src="http://www.website.nl/website/images/w3/<?php echo $merk->wiel_foto; ?>" alt="Fotonummer: <?php echo $merk->wiel_foto; ?>" class="wheelImg"/>
</a>
<span class="descr">
<img src="http://www.website.net/preview/bnet/logos/<?php echo str_replace(".png", "_100.png", $merk->merk_logo); ?>" style="padding-left:45px;" width="100" class="logo-merk" alt="<?php echo $merk->merk_naam; ?>"/>
</span>
</li>
<?php
}
?>
</ul>
<?php
}
?>
</div>
欢迎任何帮助,因为我无法弄清楚!