1
私はインターネットの周りを見回していますが、ここでもPHPの知識が不足しています。私は近くにいると感じている(まあ私は思う)。PHPフィルタ(複数のドロップダウンリスト)
携帯電話のブランドをフィルタリングできるフィルタページを作成しようとしています(たとえば、今のところ2つの機能がありますが、今までより多くの機能を追加する予定です) 。
ありがとうございます!
<?php
include('db.php'); // include your code to connect to DB.
$tbl_name="mobile"; //your table name
$sql="SELECT DISTINCT model FROM $tbl_name ORDER BY model ASC";
$result=mysql_query($sql);
$sql1="SELECT DISTINCT minutes FROM $tbl_name ORDER BY model ASC";
$result1=mysql_query($sql1);
$model_o="";
while ($row=mysql_fetch_array($result)) {
$model=$row["model"];
$model_o.="<OPTION VALUE=\"$model\">".$model;
}
$minutes_o="";
while ($row=mysql_fetch_array($result1)) {
$minutes=$row["minutes"];
$minutes_o.="<OPTION VALUE=\"$minutes\">".$minutes;
}
?>
<form action="result.php" method="post">
<SELECT NAME=Model>
<OPTION VALUE=0>Choose
<?=$model_o?>
</SELECT>
<SELECT NAME=Model>
<OPTION VALUE=0>Choose
<?=$minutes_o?>
</SELECT>
<input type="submit" value="search phones" />
</form>
result.php
<?php
include('db.php'); // include your code to connect to DB.
$tbl_name="mobile"; //your table name
$whereClauses = array();
if (! empty($_POST['Model'])) $whereClauses[] ="model='".mysql_real_escape_string($_POST['Model'])."'";
if (! empty($_POST['minutes'])) $whereClauses[] ="minutes='".mysql_real_escape_string($_POST['minutes'])."'";
$where = '';
if (count($whereClauses) > 0) { $where = ' WHERE '.implode(' AND ',$whereClauses); }
$sql = mysql_query("SELECT * FROM $tbl_name".$where);
while($row = mysql_fetch_array($sql))
{
echo "<tr>
<td><img src='".$row['image_url']."' alt='some_text'/></br>".$row['model']."</td>
<td>".$row['tariff']."</td>
<td>".$row['minimumcontractterm']."</td>
<td>".$row['minutes']."</td>
<td>".$row['texts']."</td>
<td>".$row['linerental']."</td>
<td>£".$row['dealcost']."</td>
<td>".$row['free_gift']."</td>
<td><button type='submit' class='green' onClick=parent.location='test/deal.php?id='><span>View</span></button></td>
</tr>";
// Your while loop here
}
?>
'
あなたの仕事を目で見てもらうのは常に良いことです.-ありがとう、haha :) –
問題の固定部分ですが、2番目のボックスは検索時に使用されないようですか? –