這段代碼是從SQL數據庫中選擇在線用戶及其用戶模式,在他們的用戶名之前在php輸出中添加他們的狀態前綴(〜,&,@,%,+)。結合多個foreach循環的輸出php
<< SQL Connection Data Goes here >>
//Half Mod/Half Op
$hmodsinlistsql = mysql_query("SELECT user.nick FROM `ison` INNER JOIN `user` on
`ison`.`nickid` = `user`.`nickid` INNER JOIN `chan` ON `ison`.`chanid` =
`chan`.`chanid` WHERE chan.channel = '#Channel' AND user.nick NOT LIKE
'%bot%' AND user.nick NOT LIKE '%Serv%' and user.realname NOT LIKE
'%bot%' AND user.realname NOT LIKE '%Serv' AND user.nick NOT LIKE
'%STAT%' AND user.realname NOT LIKE '%EVA%APB%' AND ison.mode_lh = 'Y' AND ison.mode_lo = 'N'
AND user.away = 'N'");
//Voiced/Temp Mod
$tempmodsinlistsql = mysql_query("SELECT user.nick FROM `ison` INNER JOIN `user` on
`ison`.`nickid` = `user`.`nickid` INNER JOIN `chan` ON `ison`.`chanid` =
`chan`.`chanid` WHERE chan.channel = '#Channel' AND user.nick NOT LIKE
'%bot%' AND user.nick NOT LIKE '%Serv%' and user.realname NOT LIKE
'%bot%' AND user.realname NOT LIKE '%Serv' AND user.nick NOT LIKE
'%STAT%' AND user.realname NOT LIKE '%EVA%APB%' AND ison.mode_lv = 'Y'
AND user.away = 'N'");
while ($row = mysql_fetch_assoc($hmodsinlistsql)) {
$rows[] = $row;
}
foreach($rows as $row) {
echo '<tr><td>%' . $row[nick] .', </td></tr>';
}
上面的代碼給了我這樣的:
%hmod2, %hmod3, %hmod4, %hmod1, %hmod5,
所需的輸出:
%hmod2, %hmod3, %hmod4, %hmod1, %hmod5, +tmod1, +tmod2, +tmod3
我的問題是,我可以得到HMOD結果正常,但是我不知道如何在單獨的查詢中有多個foreach循環,然後根據需要將結果合併到單個輸出字符串中。
如果任何人能夠幫助,這將是偉大的。
您永遠不會合並這兩個搜索結果,並且您只有一個迴響名稱的循環。 –