PDA

View Full Version : dynamic table


kevy
06-28-2008, 03:28 AM
I want my table to only list the fields that have the same SubId as the one chosen in the dropdown menu by the user. Lets call this variable $Test.

How can I only show the fields in this table where SubId = $Test?
Maybe a foreach loop? Somebody care to help?



<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>SubId</td>
<td>CatId</td>
<td>SubName</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['SubId']; ?></td>
<td><?php echo $row_Recordset1['CatId']; ?></td>
<td><?php echo $row_Recordset1['SubName']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>

kevy
06-29-2008, 03:27 AM
Got it to work :) Here's what I did:

<?php do { ?>
<tr>
<?PHP if ($row_Recordset1['SubId'] != $Selection) continue; ?>
<td><?php echo $row_Recordset1['SubId']; ?></td>
<td><?php echo $row_Recordset1['CatId']; ?></td>
<td><?php echo $row_Recordset1['SubName']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>

davidj
06-29-2008, 08:34 AM
or this


<?php do {

if ($row_Recordset1['SubId'] == $Selection) {

?>
<tr>
<td><?php echo $row_Recordset1['SubId']; ?></td>
<td><?php echo $row_Recordset1['CatId']; ?></td>
<td><?php echo $row_Recordset1['SubName']; ?></td>
</tr>
<?php }} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>