0

I am attempting to make part of a webpage, that basically shows what groups a user has joined. I want to put one table for the form 'makegroup' and another table for the 'groups owned', both these tables are part of the row of another bigger table. But however much I try the 'makegroup' is not getting displayed, and 'groupsowned' is taking its place completely. Any idea why this is happening? Should I post code?

<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>

I want to know if everything looks all right to you guys. I can;t see anything wrong, but the fact is that the form is not getting displayed :(

5
  • 1
    Yes you should post code. No one will know what you're doing wrong otherwise. You can post all the relevant code at jsfiddle.net Commented Apr 17, 2012 at 5:06
  • 1
    .. or, edit your post and append the code to it. Commented Apr 17, 2012 at 5:08
  • in if($count == 5) you should reset $count =0 Commented Apr 17, 2012 at 5:16
  • There's a much, much better-looking way to do <? if($nog==1) {echo "<br /><font color=red>Please enter a valid groupname</font>";}?>. <? if($nog==1): ?><br /><font color=red>Please enter a valid groupname</font><? endif; ?> Commented Apr 17, 2012 at 5:16
  • Hm ok.But look, the form 'makegroup' is not visible at all. Im concerned about only that right now. Commented Apr 17, 2012 at 5:18

4 Answers 4

1

You mean like this?

<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>
Sign up to request clarification or add additional context in comments.

4 Comments

No : $cont=$cont+1; after the echo "<tr>" statement and $cont=0 in the $cont==5 loop (and not 1).
I used those temporary values to test the array since I don't have whatever your mysql query array is returning. This is what it looks like jsfiddle.net/y6qYh
Woah thats how it should come! So why isnt it coming on here? :( It should be because of the sessionid condition, I guess?
I think so. You should try using print_r($_SESSION['userid']) to see what's inside the variable. Or add an else echo "user id empty" after the if($accountid == $_SESSION['userid'])
1

You had a pile of problems in your code, such as only being able to handle a single set of 5 results in the second table, incrementing a counter (so it's minimum value would always be 1) and then testing to see if it was zero, 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>

Might help.

Comments

0

Check whether this condition is matching or not: if($accountid == $_SESSION['userid'])

If it doesn't matches, then the form for makegroup won't be visible.

I have tidied up your code a bit for better readability:

    <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>

Comments

0

Few things:

1) This part...

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

...will never fire the if statement since on the first iteration $cont=1. ($cont=0+1=1)

2) You need to reset $cont after you close your if($cont==5){echo "</tr>";}} so the top section of the while statement creates a new <tr> tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.