Reputation: 119
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 :(
Upvotes: 0
Views: 501
Reputation: 10341
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 & 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.
Upvotes: 1
Reputation: 5768
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>
Upvotes: 1
Reputation: 888
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.
Upvotes: 0
Reputation: 6608
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>
Upvotes: 0