我正在尝试使网页的一部分,这基本上显示了用户加入了哪些组。我想放一个'makegroup‘表和另一个'groups owned’表,这两个表都是另一个更大的表的一部分。但是无论我怎么尝试,'makegroup‘都没有显示出来,而'groupsowned’完全取代了它的位置。你知道为什么会发生这种事吗?我应该发布代码吗?
<table width="90%" height="125" >
<tr bgcolor="#CCCCCC"><td height="20" colspan="2"><h4>Groups</h4>
</td></tr>
<tr bgcolor="#CCCCCC">
<?
if($accountid == $_SESSION['userid'])
{
?>
<td width="50%">
<form name="groupscreate" method="post" onsubmit="return Confirm()">
<table width="99%" height="6%" bgcolor="#CCCCCC"> <tr valign="top">
<td colspan="3"><h5>Create Groups</h5></td></tr>
<tr><td>
<input align="absmiddle" type="text" maxlength="25" name="gname" /><? if($nog==1) {echo "<br /><font color=red>Please enter a valid groupname</font>";}?></td>
<td><select name="gcategory">
<option value="General" selected>General</option>
<option value="Comedy">Comedy</option>
<option value="Education">Education</option>
<option value="Entertainment">Entertainment</option>
<option value="Gaming">Gaming</option>
<option value="Music">Music</option>
<option value="Science & Technology">Science & Technology</option>
<option value="Sports">Sports</option>
</select></td><td><input type="submit" name="makegroup" value="create group"/></td></tr>
</table>
</form>
</td>
<?
}
$grp= "SELECT * from groups where accountid='". $accountid."'";
$rest = mysql_query($grp,$connection);
$cont=0;
?>
<td width="50%" >
<table width="100%" height="20%" bgcolor="#CCCCCC" >
<tr><td colspan="10"><h5>Groups Owned</h5>
</td></tr>
<?
while($grow=mysql_fetch_array($rest))
{
$cont=$cont+1;
$gid=$grow['groupid'];
$gnam=$grow['groupname'];
$gcreator=$grow['accountid'];
if($cont==0)
{
echo "<tr>";
}
echo "<td align='left' ><a href='groups_discussions.php?id=".$gid."'><font color="."#333333"." size='-1'>".$gnam."</font></a></td>";
if($cont==5)
{echo "</tr>";}
}
?>
</table>
</td>
</tr></table>我想知道你们是不是觉得一切都好。我看不出有什么问题,但事实是表单没有显示出来:
发布于 2012-04-17 13:48:43
你是说像这样吗?
<table width="90%" height="125" bgcolor="orange">
<tr bgcolor="#CCCCCC"><td height="20" colspan="2"><h4>Groups</h4></td></tr>
<tr bgcolor="#CCCCCC">
<td width="50%">
<form name="groupscreate" method="post" onsubmit="return Confirm()">
<table width="99%" height="6%" bgcolor="green">
<tr valign="top">
<td colspan="3"><h5>Create Groups</h5></td>
</tr>
<tr bgcolor="blue">
<td bgcolor="orange">
<input align="absmiddle" type="text" maxlength="25" name="gname" />
<?php
$nog = 1;
if($nog == 1)
echo "<br /><font color=red>Please enter a valid groupname</font>";
?>
</td>
<td bgcolor="yellow">
<select name="gcategory">
<option value="General" selected>General</option>
<option value="Comedy">Comedy</option>
<option value="Education">Education</option>
<option value="Entertainment">Entertainment</option>
<option value="Gaming">Gaming</option>
<option value="Music">Music</option>
<option value="Science & Technology">Science & Technology</option>
<option value="Sports">Sports</option>
</select>
</td>
<td bgcolor="red">
<input type="submit" name="makegroup" value="create group"/>
</td>
</tr>
</table>
</form>
</td>
<td width="50%">
<table width="100%" height="20%" bgcolor="pink" >
<tr><td colspan="10"><h5>Groups Owned</h5></td></tr>
<?php
//$grp= "SELECT * from groups where accountid='". $accountid."'";
//$rest = mysql_query($grp, $connection);
$rest = array(
array('groupid' => '123', 'groupname' => 'testname', 'accountid' => '456'),
array('groupid' => '678', 'groupname' => 'testname2', 'accountid' => '999')
);
$cont = 0;
foreach ($rest as $grow)
{
$gid = $grow['groupid'];
$gnam = $grow['groupname'];
$gcreator = $grow['accountid'];
if($cont == 0)
echo "<tr>";
echo "<td align='left' ><a href='groups_discussions.php?id=" . $gid . "'><font color="."#333333"." size='-1'>" . $gnam . "</font></a></td>";
if($cont == 1)
echo "</tr>";
$cont = $cont + 1;
}
?>
</table>
</td>
</tr>
</table>发布于 2012-04-17 14:30:47
您的代码中有一大堆问题,比如只能处理第二个表中的一组5个结果,递增一个计数器(因此它的最小值始终为1),然后测试它是否为零,等等。
<table width="90%" height="125" >
<tr bgcolor="#CCCCCC">
<td height="20" colspan="2">
<h4>Groups</h4>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<?
if( isset( $_SESSION['userid'] ) && $accountid==$_SESSION['userid'] ){
?>
<td width="50%">
<form name="groupscreate" method="post" onsubmit="return Confirm()">
<table width="99%" height="6%" bgcolor="#CCCCCC">
<tr valign="top">
<td colspan="3">
<h5>Create Groups</h5>
</td>
</tr>
<tr>
<td>
<input align="absmiddle" type="text" maxlength="25" name="gname" />
<?
if( $nog==1 ){
?>
<br /><font color="red">Please enter a valid groupname</font>
<?php
}
?>
</td>
<td>
<select name="gcategory">
<option value="General" selected>General</option>
<option value="Comedy">Comedy</option>
<option value="Education">Education</option>
<option value="Entertainment">Entertainment</option>
<option value="Gaming">Gaming</option>
<option value="Music">Music</option>
<option value="Science & Technology">Science & Technology</option>
<option value="Sports">Sports</option>
</select>
</td>
<td>
<input type="submit" name="makegroup" value="create group" />
</td>
</tr>
</table>
</form>
</td>
<?
}
$grp = "SELECT * from groups where accountid='{$accountid}'";
$rest = mysql_query( $grp , $connection );
$cont = 0;
?>
<td width="50%" >
<table width="100%" height="20%" bgcolor="#CCCCCC" >
<tr>
<td colspan="10">
<h5>Groups Owned</h5>
</td>
</tr>
<?
if( mysql_num_rows( $rest )>0 ){
while( $grow = mysql_fetch_array( $rest ) ){
$gid = $grow['groupid'];
$gnam = $grow['groupname'];
$gcreator = $grow['accountid'];
if( ( $cont%5 )==0 )
echo '<tr>';
echo "<td align='left' ><a href='groups_discussions.php?id={$gid}'><font color='#333333' size='-1'>{$gnam}</font></a></td>\n";
if( ( $cont%5 )==4 )
echo '</tr>';
$cont++;
}
}else{
echo '<tr><td colspan="10">No Records</td></tr>';
}
?>
</table>
</td>
</tr>
</table>也许能帮上忙。
发布于 2012-04-17 13:27:24
检查该条件是否匹配:if($accountid == $_SESSION['userid'])
如果不匹配,则makegroup的表单将不可见。
为了更好的可读性,我整理了一下你的代码:
<table width="90%" height="125" >
<tr bgcolor="#CCCCCC">
<td height="20" colspan="2"><h4>Groups</h4></td>
</tr>
<tr bgcolor="#CCCCCC">
<?
if($accountid == $_SESSION['userid'])
{
?>
<td width="50%">
<form name="groupscreate" method="post" onsubmit="return Confirm()">
<table width="99%" height="6%" bgcolor="#CCCCCC">
<tr valign="top">
<td colspan="3"><h5>Create Groups</h5></td>
</tr>
<tr>
<td>
<input align="absmiddle" type="text" maxlength="25" name="gname" />
<? if($nog==1) {echo "<br /><font color=red>Please enter a valid groupname</font>";}?>
</td>
<td>
<select name="gcategory">
<option value="General" selected>General</option>
<option value="Comedy">Comedy</option>
<option value="Education">Education</option>
<option value="Entertainment">Entertainment</option>
<option value="Gaming">Gaming</option>
<option value="Music">Music</option>
<option value="Science & Technology">Science & Technology</option>
<option value="Sports">Sports</option>
</select>
</td>
<td>
<input type="submit" name="makegroup" value="create group"/>
</td>
</tr>
</table>
</form>
</td>
<?
}
$grp= "SELECT * from groups where accountid='". $accountid."'";
$rest = mysql_query($grp,$connection);
$cont=0;
?>
<td width="50%" >
<table width="100%" height="20%" bgcolor="#CCCCCC" >
<tr>
<td colspan="10"><h5>Groups Owned</h5></td>
</tr>
<?
while($grow=mysql_fetch_array($rest))
{
$cont=$cont+1;
$gid=$grow['groupid'];
$gnam=$grow['groupname'];
$gcreator=$grow['accountid'];
if($cont==0)
echo "<tr>";
echo "<td align='left' ><a href='groups_discussions.php?id=".$gid."'><font color="."#333333"." size='-1'>".$gnam."</font></a></td>";
if($cont==5)
echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>https://stackoverflow.com/questions/10185350
复制相似问题