簡體   English   中英

使用php顯示多個SQL查詢結果

[英]Display multiple sql query results using php

好的,我進行了搜索,但仍在努力解決問題。 這是我目前的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

一切都很好,問題已得到解決。 感謝您的所有幫助:) PS這是我輸入的代碼:

$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代碼,但現在一切都很好。 再次感謝。

嘗試這個:

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

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

要計算發現的所有行,請點擊此處

小提示:

  • 請停止使用mysql,已棄用
  • 改用mysqliPDO
  • 使用字符串索引數組時,請始終使用引號

做出改變

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

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM