PHP的循环取值问题?

2024-12-26 07:17:53
推荐回答(5个)
回答1:

PHP code$keywords=$_POST['keyword'];
if($keywords!=null){
$host="localhost";
$user="root";
$pass="123";
$db="test";
$connection=mysql_connect($host,$user,$pass) or die ("Unable to connect!");
mysql_select_db($db) or die("Unable to select database!");
mysql_query("SET NAMES 'utf-8'");
$query="select title from test where title like '%$kewords%' order by id desc limit 10";
$result=mysql_query($query) or die("Erro in query:$query.".mysql_erro());
while($row=mysql_fetch_array($result)){
echo $row('title')."
";
}
?>

看看行不行

回答2:

你的查询是没有错的 错的是你显示那里吧
你已经能够循环了

回答3:

$query="select title,id,from test where title like '%$kewords%' group by title order by id desc ";
$result =mysql_query ($sql);
$rows=mysql_affected_rows($connection)or die(mysql_error());
$i=0;
if($rows>10)
while($row = mysql_fetch_row($result)&&$i<10)
{
echo $row[0];
$i++;
}
else {
echo "not enough titles";
exit;
}

回答4:

echo "

\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t\n";
foreach ($line as $col_value) {
echo "\t\t\n";
}
echo "\t\n";
}
echo "
$col_value
\n";

回答5:

你这个SQL语句好像有问题啊。id都没查出来。怎么按降序排列啊?