<?php
ini_set('display_errors', 0);
$search = $_GET ['search'];
mysql_connect("localhost", "root", "gokul");
mysql_select_db("search123");
$query = mysql_query("SELECT * FROM search WHERE name LIKE '%" . $queryString . "%'");
$foundnum = mysql_num_rows($query);
if ($foundnum == 0) {
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
meaning</br>3. Please check your spelling<br/>4.PLEASE DON'T USE SPACES";
}
else {
echo "$foundnum results found !<p>";
$row = mysql_fetch_assoc($query);
{
$title = $runrows ['title'];
$desc = $runrows ['description'];
$url = $runrows ['url'];
echo "<a href=$row[url]>$row[name]</a><br><font color=green>$row[url]</font><br>$row[desc]<br/>";
}
}
?>这是我的搜索引擎脚本。这个脚本只显示一个结果。如何使用php将其更改为显示多种结果
发布于 2012-03-29 22:39:28
更改为:
while ($row = mysql_fetch_assoc($query)) {
$title = $runrows ['title'];
$desc = $runrows ['description'];
$url = $runrows ['url'];
echo "<a href=$row[url]>$row[name]</a><br><font color=green>$row[url]</font><br>$row[desc]<br/>";
}发布于 2012-03-29 22:51:10
对Elen的(正确的)答案有更多的解释。mysql_fetch_assoc()从结果集中提取一条记录。您可以重复调用它来依次获取每条记录。一旦获取了最后一条记录,"$row = mysql_fetch_assoc($query)“将失败。因此,您可以在while循环中使用该表达式来获取每一行,并在完成时停止。
发布于 2012-03-29 22:40:34
在这里,mysql_fetch_assoc您只是获取结果,而不是循环它们。http://php.net/manual/en/function.mysql-fetch-assoc.php
使用foreach()或任何循环方法可获得更多结果。
https://stackoverflow.com/questions/9927591
复制相似问题