我有两个mysql表: 1个案例(包含许多列)其中之一是(案例类型) 2种类型(包含2列): casetypeID,casetypename
案例类型在案例表中另存为ID。
当我想显示它时显示为Number。
我需要为casetypeID加入Join ID,以将casetype显示为名称而不是数字。
谢谢
<?php
$connect = mysqli_connect("localhost", "user", "pass", "data");
$connect->set_charset('utf8');
$query = "SELECT casetype, count(*) as number FROM cases GROUP BY casetype";
$result = mysqli_query($connect, $query);
?>
<!DOCTYPE html>
<html dir=rtl>
<meta charset="UTF-8">
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart()
{
var data = google.visualization.arrayToDataTable([
['casetype', 'Number'],
<?php
while($row = mysqli_fetch_array($result))
{
echo "['".$row["casetype"]."', ".$row["number"]."],";
}
?> ```
答案 0 :(得分:0)
SELECT `types`.casetypeName, count(*) as number FROM cases
inner join `types` on `types`.casetypeID = cases.casetype
GROUP BY cases.casetype
此查询将连接两个关于casetypeID和casetype的表,并从类型表中选择casetypeName。