使用php显示多个sql查询结果

时间:2013-01-29 09:33:31

标签: php sql

好的,所以我搜索和搜索但仍在努力解决我的问题。这是我目前的PHP编码:

$show = "Select effectiveness, round((Count(effectiveness)* 100 / (Select Count(*) From acupuncture))) as Score
From acupuncture
Group By effectiveness
ORDER BY Score DESC";
$result = mysql_query ($show);

WHILE($show = mysql_fetch_array($result))
{
$field1 = $show[effectiveness];
$field2 = $show[Score];

echo "$field1: ";
echo "$field2%<br><br>";
}

除了显示上述内容外,我还想显示表格中的行数。我知道sql代码是:

"SELECT COUNT(id) AS entries FROM acupuncture"

问题是,当我尝试将此输入到我的php页面时,我一直收到错误。我想在一个php页面上显示两个SELECT语句结果。如果有人可以提供帮助,我会非常感激。

谢谢 Shikz

一切都很好,问题已得到解决。谢谢你的帮助:) P.S.这是我输入的代码:

$size = @mysql_query("SELECT COUNT(*) AS `total` FROM acupuncture");
$query = mysql_fetch_array($size);
echo "Number of entries: ";
echo $query['total'];
echo "<br><br>";

之前我错误地编写了php代码,但现在一切都很好。再次感谢。

2 个答案:

答案 0 :(得分:1)

试试这个:

while($show = mysql_fetch_assoc($result))
{
  $field1 = $show['effectiveness'];
  $field2 = $show['Score'];

  echo "$field1: ";
  echo "$field2%<br/><br/>";
}

要找到所有找到的行here

小提示:

答案 1 :(得分:0)

中进行更改
WHILE($show = mysql_fetch_array($result))
{
   $field1 = $show[effectiveness];
   $field2 = $show[Score];

   echo "$field1: ";
   echo "$field2%<br><br>";
}

TO

WHILE($row= mysql_fetch_array($result))
{
   $field1 = $row[effectiveness];
   $field2 = $row[Score];

   echo "$field1: ";
   echo "$field2%<br><br>";
}