我有以下代码:
$getrand = "SELECT DISTINCT Name from Events Order BY Rand() Limit 1";
$result = mysqli_query($con,$getrand);
$data = mysqli_fetch_array($result);
echo "<div class = 'container'>Name: $data[0]</br>";
$gettags = "SELECT Tag From Events where Name = '$data[0]'";
$tagresult = mysqli_query($con, $gettags);
$tagdata = mysqli_fetch_array($tagresult);
echo "$tagdata[0], $tagdata[1]";
但是它只返回一个值tagdata
。我的数据库看起来像:
身份证 | 姓名 | 标签
一个名字可以有多个标签(即每个名字有多行标签)