PHP多查询合并两张数据表展示列表问题(第二次尝试)
问题说明
我正在尝试合并两张数据表,但所有结果都集中在一组内,需要将结果分散到多组中。此前有网友回复了一段代码片段,但我未能完全理解。我已修正了代码中的一处错误(原代码使用了不同的SQL连接变量),但目前仍遇到问题。
当前运行效果

当前代码
<?php $con = new mysqli("-", "-", "-", "-"); $con->set_charset('utf8mb4'); //Retrieve all the data from the Update Log Table $result = $con->query("SELECT StreamDayID, WeekColor, DayName, StreamTitle, StreamGame, TIME_FORMAT(StartTime, '%r') AS StartTime, DATE_FORMAT(StreamDate, '%D %b') AS StreamDate FROM `WeekData` WHERE WeekColor='Blue'") or die(mysql_error()); //Retrieve all the data from the Update Log Table //$joinresult = $con->query("SELECT JoinID, JoinedBy, StreamID FROM `JoinedBy` INNER JOIN `WeekData` ON StreamID = StreamDayID") or die(mysql_error()); echo "<div id='blue' class='day'>"; echo "<h1 class='row'>Blue:</h1>"; //keeps getting the next row until there are no more to get while($row = mysqli_fetch_array($result)){ $joinresult = $con->stmt_init(); $joinresult->prepare("SELECT JoinID, JoinedBy, StreamID FROM `JoinedBy` WHERE StreamID = ?"); // if `StreamDayID` is an integer, change "s" -> "i" $joinresult->bind_param("s", $row['StreamDayID']); $exec = $joinresult->execute(); if(!$exec){ // error die(mysql_error()); } //Print out the contents of each row into a table echo "<div id='blue"; echo $row['StreamDayID']; echo "' class='les'>"; echo "<div class='title'>"; echo "<h2>"; echo $row['StreamTitle']; echo "</h2>"; echo "</div>"; echo "<div class='detail'>"; echo "<h4>Day: "; echo $row['DayName']; echo "</h4>"; echo "<h4>Game: "; echo $row['StreamGame']; echo "</h4>"; echo "<h4 class='joiners'>Joined By:"; while($join = mysqli_fetch_array($joinresult)){ echo "<a class='delink' href='https://twitch.tv/"; echo $join['JoinedBy']; echo "'>"; echo $join['JoinedBy']; echo "</a>"; }; echo "</h4>"; echo "<h4>Start Time: "; echo $row['StartTime']; echo "</h4>"; echo "<h4>Stream Date: "; echo $row['StreamDate']; echo "</h4>"; echo "</div>"; echo "</div>"; }; ?>
期望实现效果

内容的提问来源于stack exchange,提问作者Kiddabob Stamp
相关产品推荐
相关产品推荐

