Web サイトの検索スクリプトを作成しようとしています。ここまでは順調ですが、検索結果が無ければ「表示する結果がありません」と表示させたい。私はこれを試しました:
<?php
while($resultsarray(mysql_fetch_assoc($searchresult))//$searchresult is the result of my MySQL query
{
if($_GET['options']=='user') {
echo "<a href = 'userinfo.php?id=".$resultsarray['usernum']."'>".$resultsarray['username']."</a>";
}
else if($_GET['options']=='topics') {
echo "<a href = 'display_post.php?id=".$resultsarray['id']."'>".$resultsarray['subject']."</a>";
echo "<p>".$resultsarray['content']."</p>";
}
}
if(empty($resultsarray)) {
echo "<p>There are no results to display.</p>";
}
しかし、結果があったとしても、常にメッセージが表示されました。私もこれを試しました:
<?php
$resultsarray = mysql_fetch_assoc($searchresult);
if(empty($resultsarray)) {
echo "<p>There are no results to display.</p>";
}
while($resultsarray = mysql_fetch_assoc($searchresult))//$searchresult is the result of my MySQL query
{
if($_GET['options']=='user') {
echo "<a href = 'userinfo.php?id=".$resultsarray['usernum']."'>".$resultsarray['username']."</a>";
}
else if($_GET['options']=='topics') {
echo "<a href = 'display_post.php?id=".$resultsarray['id']."'>".$resultsarray['subject']."</a>";
echo "<p>".$resultsarray['content']."</p>";
}
}
しかし、それもうまくいきませんでした。この問題に関するヘルプは大歓迎です。