我有一个正在阅读我的车轮品牌的脚本。如果我选择一个轮子,它会显示该品牌的所有轮子......
但是因为我做了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>
欢迎任何帮助,因为我无法理解!
答案 0 :(得分:0)
由于SQL中的某些字段不匹配,您将获得双打,因此您可以获得每个字段的记录。