私は注文カートのための基本的な検索機能を作成しています。最後のレコード結果のテーブルクロージャを作成します
$dataQuery = "SELECT * FROM `products` WHERE upper(`desc`) LIKE'%$find%'";
$data = mysql_query($dataQuery) or die(mysql_error());
$pageContent .= '
<table border="1">
<thead>
<tr>
<th>Stock Code</th>
<th>Description</th>
<th>Packsize</th>
<th>Price</th>
<th>In-Stock?</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
';
//And we display the results
while($result = mysql_fetch_array($data))
{
$prId = $result['id'];
$prRefCode = $result['refCode'];
$prDesc = $result['desc'];
$prPack = $result['pack'];
$prMeasure = $result['measure'];
$prQuantity = $result['quantity'];
$prDeptCode = $result['deptCode'];
$prTaxable = $result['taxable'];
$prPrice1 = $result['price1'];
$prPrice2 = $result['price2'];
$prCrdCode = $result['crdCode'];
$prCost1 = $result['cost1'];
$prCost2 = $result['cost2'];
$pageContent .= '
<tr>
<td>'.$prId.'</td>
<td>'.$prDesc.'</td>
<td>'.$prPack.'x'.$prSize.' '.$prMeasure.'</td>
<td>R'.$prPrice1.'</td>
';
if (empty($prQuantity)) {
$pageContent .= '
<td>No</td>
';
} else {
$pageContent .= '
<td>Yes</td>
';
}
$pageContent .= '
<td>
<form action="" method="post">
<div>
<input type="hidden" name="id" value="'.$prId.'" />
<input type="submit" name="action" value="Order" />
</div>
</form>
</td>
</tr>
';
}
$pageContent .= '
</tbody>
</table>
';
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
$pageContent .= '
<p>Sorry, but we can not find an entry to match your query</p>
';
}
//And we remind them what they searched for
$pageContent .= '
<p><b>Searched For:</b> '.$find.'</p>
';
}
$pageContent .= '
<br />
<p>All prices are inclusive of VAT</p>
';
あなたが見ることができるように、これはWHERE句に一致するテーブルの製品の各行を表示する表を生成します。私はこのようになりますループを持っています。
私がしたいのは、最後の出現を最後のループ結果に加えた$pageContent
にして、効果的にテーブルを閉じることです。これのoccuranceは次のようになります
$pageContent .= '
</tbody>
</table>
';
、私は結果を効果的にテーブルを開くと呼ばれるようにループの前directely添加$pageContent
の最初のoccuranceしたいと思います。これのoccuranceは、次のようになります。
$pageContent .= '
<table border="1">
<thead>
<tr>
<th>Stock Code</th>
<th>Description</th>
<th>Packsize</th>
<th>Price</th>
<th>In-Stock?</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
';
私が直面しています問題は、ユーザーが無効な文字列、段落を検索する場合は、「申し訳ありませんが、私たちはあなたのクエリに一致するエントリを見つけることができない」ということです
は、テーブルの下に出力を取得しますヘッダーには、行が割り当てられていません。ユーザーが無効な検索オプションを入力すると、有効な検索文字列の出現にのみ適用する必要があるテーブルヘッダーなしで、この段落が単独で表示されるという効果を出そうとしています。
誰かがこれに関するいくつかの入力を持っているなら、私は本当にそれを感謝します!
マイワード!!!そんなに簡単なアプローチでした。ありがとうございました。あなたは私が試している狂ったものが何であるか分かりません!本当にありがとう! –
ハ...それは問題ではない、あなたは大歓迎です。私はあなたを信じている、私はいくつかの狂った、多くのシンプルなはずだったはずだったものを達成するためのトップアプローチを何度も取った... – BumbleShrimp