Jump to content

How can I fix this dynamic table?


kevy

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/112295-how-can-i-fix-this-dynamic-table/
Share on other sites

What's wrong with this code?

 

 

<?php for ($row_Recordset1['SubId'] = $Test);

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)); ?>

you mean something like this?

 

<table>
<?php foreach($row = mysql_fetch_array($result)) : ?>
<?php if($row['subId'] == $test) : ?>
<tr><td>Data here</td></tr>
<?php endif ; ?>
<?php endforeach ; ?>
</table>

 

 

 

 

 

I entered the code you suggested, and get the error "Parse error: syntax error, unexpected ')' in C:\xampp\htdocs\antiques\form_processor.php on line 53"

 

This is the line <?php foreach($row = mysql_fetch_array($result)) : ?>

 

Any idea what's wrong?

Got it to work. Thanks for the help everybody. This is what worked:

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.