0

我正在尝试制作网页的一部分,该网页基本上显示了用户加入了哪些组。我想为“makegroup”表格放置一个表格,为“拥有的组”放置另一个表格,这两个表格都是另一个更大表格的行的一部分。但是无论我怎么尝试,“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>

我想知道你们看起来是否一切都好。我看不出有什么问题,但事实是表单没有显示:(

4

4 回答 4

1

你的意思是这样吗?

<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-17T05:48:42.743 回答
1

您的代码中有一堆问题,例如只能处理第二个表中的一组 5 个结果,递增一个计数器(因此它的最小值始终为 1)然后测试它是否为零, ETC。

<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 &amp; 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-17T06:30:46.627 回答
0

检查此条件是否匹配: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>
于 2012-04-17T05:27:24.150 回答
0

一些事情:

1) 这部分...

 $cont=$cont+1;
 $gid=$grow['groupid'];
 $gnam=$grow['groupname'];
 $gcreator=$grow['accountid'];
 if($cont==0)
    {
    echo "<tr>"; 
    }

...不会触发 if 语句,因为在第一次迭代 $cont=1 时。($cont=0+1=1)

2)您需要在关闭后重置 $contif($cont==5){echo "</tr>";}}以便 while 语句的顶部创建一个新<tr>标签。

于 2012-04-17T05:30:15.713 回答