주문 장바구니에 대한 기본 검색 기능을 생성 중입니다.마지막 레코드 결과에 테이블 닫기 생성
당신이 볼 수 있듯이$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 절과 일치하는 테이블 제품의 각 행을 표시하는 테이블을 생성합니다 I는 다음과 같습니다 루프를 가지고있다.
내가 마지막으로 수행 한 결과는 마지막 루프 결과에 $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