我试图拉出if语句并将它们放入一个表格中,它会返回一个新行""每5个结果"图像"。是否有可能使用这个功能?我必须像这样使用它的原因是因为Mybb的设置方式。它可以从许多细胞中拉出来,也可以尝试在其中挑选出25个细胞系的细胞,而不是特定的间隔物......只是一切都塞满了。我已经测试了很多不同的东西,但可以让任何工作。每次谷歌搜索都会出现与我的搜索有关的内容,但通常是关于不同的页面。
$queryleader= mysql_query("SELECT * FROM pju_users WHERE `uid` = '1'") or die(mysql_error());
while($dataleader = mysql_fetch_array($queryleader)){
$queryfid = mysql_query("SELECT * FROM pju_userfields WHERE `ufid` = '".$dataleader['uid']."'") or die(mysql_error());
while($dataufid = mysql_fetch_array($queryfid)){
echo "<tr>";
if ($dataleader['avatar'] == ""){
echo "<td><Img src='images/default_member.png' height='50' width='50' title='" . $dataleader['username'] . "''/></td>";
}else{
echo "<td><Img src='uploads/avatars/avatar_" . $dataleader['uid'] . ".jpg' height='50' width='50' title='" . $dataleader['username'] . "''/></td>";
}
echo '<td align="left">';
echo "<div style='margin:0; padding:0; font-family:Arial,Helvetica,sans-serif'><font size='3'>.GoD|" . $dataleader["username"] . "</font><br /><font size='1'> Founder</font></div>";
echo '</td><td> </td><td> </td><td> </td>';
echo "<td align='center'><img src='images/flags/" . $dataufid['fid1'] . ".png' title='" . $dataufid['fid1'] . "'></td><td> </td><td> </td><td> </td>";
if ($dataleader['away'] == "1"){
echo '<td align="center"><font color="#9d0000">Inactive</font></td> ';
}
elseif ($dataleader['away'] == "0"){
echo '<td align="center"><font color="#219b00">Active</font></td>';
}
if ($dataufid['fid5'] != NULL) {
echo "<td> </td><td> </td><td> </td><td align='center'><a href='http://steamcommunity.com/id/" . $dataufid['fid5'] . "'>" . $dataleader["username"] . "</a></td>";
}elseif ($dataufid['fid8'] != NULL) {
echo "<td> </td><td> </td><td> </td><td align='center'><a href='http://steamcommunity.com/profiles/" . $dataufid['fid8'] . "'>" . $dataleader["username"] . "</a></td>";
}else{
echo "<td> </td><td> </td><td> </td><td></td>";
}
echo "<td><table><tr>";
////////////////////////////////////////////
// //
// //
//THIS IS THE PART I NEED POST 5 PER ROW //
// //
// //
////////////////////////////////////////////
//Americas Army
if ($dataufid['fid9'] == "Yes") {
echo '<td><img src="images/games/AA.png" title="Americas Army"/></td>';
}
//Arma 2
if ($dataufid['fid10'] == "Yes") {
echo '<td><img src="images/games/Arma2.png" title="Arma 2"/></td>';
}
//Arma 3
if ($dataufid['fid11'] == "Yes") {
echo '<td><img src="images/games/Arma3.png" title="Arma 3"/></td>';
}
//Breaking Point
if ($dataufid['fid12'] == "Yes") {
echo '<td><img src="images/games/BP.png" title="Breaking Point"/></td>';
}
//Battleroyal
if ($dataufid['fid13'] == "Yes") {
echo '<td><img src="images/games/BR.png" title="Battleroyal"/></td>';
}
//BF3
if ($dataufid['fid14'] == "Yes") {
echo '<td><img src="images/games/BF3.png" title="Battlefield 3"/></td>';
}
//BF4
if ($dataufid['fid15'] == "Yes") {
echo '<td><img src="images/games/BF4.png" title="Battlefield 4"/></td>';
}
//Borderlands 1
if ($dataufid['fid16'] == "Yes") {
echo '<td><img src="images/games/Borderlands.png" title="Borderlands"/></td>';
}
//Borderlands 2
if ($dataufid['fid17'] == "Yes") {
echo '<td><img src="images/games/Borderlands2.png" title="Borderlands 2"/></td>';
}
//CoD:MW
if ($dataufid['fid18'] == "Yes") {
echo '<td><img src="images/games/COD_MW.png" title="CoD Modern Warfare"/></td>';
}
//COD:MW2
if ($dataufid['fid19'] == "Yes") {
echo '<td><img src="images/games/COD_MW2.png" title="CoD Modern Warfare2"/></td>';
}
//COD:MW3
if ($dataufid['fid20'] == "Yes") {
echo '<td><img src="images/games/COD_MW3.png" title="CoD Modern Warfare3"/></td>';
}
//COD:BO
if ($dataufid['fid21'] == "Yes") {
echo '<td><img src="images/games/COD_BO.png" title="CoD Black Ops"/></td>';
}
//COD:BO2
if ($dataufid['fid22'] == "Yes") {
echo '<td><img src="images/games/COD_BO2.png" title="CoD Black Ops 2"/></td>';
}
//COD:Ghost
if ($dataufid['fid23'] == "Yes") {
echo '<td><img src="images/games/COD_Ghosts.png" title="CoD Ghosts"/></td>';
}
//COD:AW
if ($dataufid['fid24'] == "Yes") {
echo '<td><img src="images/games/AW.png" title="CoD Advanced Warfare"/></td>';
}
//Deadisland
if ($dataufid['fid25'] == "Yes") {
echo '<td><img src="images/games/Deadisland.png" title="Dead Island"/></td>';
}
//COD:League of Legends
if ($dataufid['fid26'] == "Yes") {
echo '<td><img src="images/games/LoL.png" title="League of Legends"/></td>';
}
//CS
if ($dataufid['fid27'] == "Yes") {
echo '<td><img src="images/games/CS.png" title="Counterstrike"/></td>';
}
//CS-GO
if ($dataufid['fid28'] == "Yes") {
echo '<td><img src="images/games/CS_GO.png" title="Counterstrike:GO"/></td>';
}
//DayZ
if ($dataufid['fid29'] == "Yes") {
echo '<td><img src="images/games/Dayz.png" title="DayZ"/></td>';
}
//L4D
if ($dataufid['fid30'] == "Yes") {
echo '<td><img src="images/games/L4D.png" title="Left 4 Dead"/></td>';
}
//L4D2
if ($dataufid['fid31'] == "Yes") {
echo '<td><img src="images/games/L4D2.png" title="Left 4 Dead 2"/></td>';
}
//starcraft
if ($dataufid['fid32'] == "Yes") {
echo '<td><img src="images/games/Starcraft.png" title="Starcraft"/></td>';
}
//starcraft
if ($dataufid['fid33'] == "Yes") {
echo '<td><img src="images/games/Starcraft2.png" title="Starcraft 2"/></td>';
}
echo "</table></td></tr>";
}
}
答案 0 :(得分:0)
这样的事情可能会给你更好的想法=
<?php
$a = array('a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a');
echo "<table>";
echo "<tr>";
for($i = 1; $i <= sizeof($a); $i++)
{
echo "<td>".$a[$i-1]."</td>";
if($i % 5 == 0)
{
echo "</tr><tr>";
}
}
echo "</tr>";
echo "</table>";
答案 1 :(得分:0)
使用
$colsToDisplay = 6;
$htmlOutput = array();
我能够像这样使用if标签
if ($dataufid['fid9'] == "Yes") {
$htmlOutput[] = '<td><img src="images/games/AA.png" title="Americas Army"/></td>';
}
然后
$htmlOutput = array_chunk($htmlOutput, $colsToDisplay);
foreach($htmlOutput as $currRow) {
print '<tr>' . implode('', $currRow) . '</tr>';
}
像魅力一样工作