我尝试使用mysql_fetch_array从MySQL数据库中回显出一系列行,同时循环到带有表单的表中。我尝试不重复form-table和/ table- / form标签,但只在回显时重复tr ... / tr标签。
虽然,它也在重复form-table和/ table- / form标签。 任何人都可以帮忙。我只想重复tr ... / tr。 以下是代码:
$topmessage = '<form><table width="100%" border="0" cellspacing="0" cellpadding="10">';
$bottommessage = '</table><div align="right"><input type="submit" name="approveimage" value="Approve" /><input type="submit" name="disapproveimage" value="Disapprove" /></div></form>';
$multirowing = '';
require("../connect.php");
$query2 = "SELECT * FROM imagegallery WHERE approve ='0'";
$result2 = mysql_query($query2);
while($rowphew = mysql_fetch_array($result2))
{
$multirowing .= '<tr>
<td>' . $rowphew['username'] . '</td>
<td>
<a href="uploads/' . $rowphew['image'] . '">
<img src="uploads/' . $rowphew['image'] . '" width="100px" />
</a>
</td>
<td>
<input type="checkbox" name="selectingimage" value="' . $rowphew['image'] . '" />
</td>
</tr>';
}
$message = $topmessage . $multirowing . $bottommessage;
echo $message;
给出的结果结果(如源代码所示):(抱歉上传图片需要10点声望点..hh)
<form><table>
<tr><td>Image1</td></tr>
</table>BUTTONS</form>
<form><table>
<tr><td>Image1</td></tr>
<tr><td>Image2</td></tr>
</table>BUTTONS</form>
<form><table>
<tr><td>Image1</td></tr>
<tr><td>Image2</td></tr>
<tr><td>Image3</td></tr>
</table>BUTTONS</form>
<form><table>
<tr><td>Image1</td></tr>
<tr><td>Image2</td></tr>
<tr><td>Image3</td></tr>
<tr><td>Image4</td></tr>
</table>BUTTONS</form>
<form><table>
<tr><td>Image1</td></tr>
<tr><td>Image2</td></tr>
<tr><td>Image3</td></tr>
<tr><td>Image4</td></tr>
<tr><td>Image5</td></tr>
</table>BUTTONS</form>
答案 0 :(得分:0)
您需要将字符串附加到$multirowing
,而不是替换它。你应该使用htmlentities。
$topmessage = '<form><table width="100%" border="0" cellspacing="0" cellpadding="10">';
$bottommessage = '</table><div align="right"><input type="submit" name="approveimage" value="Approve" /><input type="submit" name="disapproveimage" value="Disapprove" /></div></form>';
$multirowing = '';
require("../connect.php");
$query2 = "SELECT * FROM imagegallery WHERE approve ='0'";
$result2 = mysql_query($query2);
while($rowphew = mysql_fetch_array($result2))
{
$multirowing .= '<tr>
<td>' . htmlentities($rowphew['username']) . '</td>
<td><a href="uploads/' . htmlentities($rowphew['image']) . '"><img src="uploads/' . htmlentities($rowphew['image']) . '" width="100px" /></a></td>
<td>
<input type="checkbox" name="selectingimage" value="' . htmlentities($rowphew['image']) . '" />
</td>
</tr>';
}
$message = $topmessage . $multirowing . $bottommessage;
echo $message;
答案 1 :(得分:0)
除了不推荐使用msql_query这一事实之外(你应该转移到PDO)。
您正在设置$multirowing = '<tr>....'
我认为您希望将其更改为$multirowing .= '<tr>....'
这是在另一个循环中吗?