kevy Posted June 28, 2008 Share Posted June 28, 2008 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 More sharing options...
kevy Posted June 28, 2008 Author Share Posted June 28, 2008 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)); ?> Link to comment https://forums.phpfreaks.com/topic/112295-how-can-i-fix-this-dynamic-table/#findComment-576548 Share on other sites More sharing options...
vbnullchar Posted June 28, 2008 Share Posted June 28, 2008 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> Link to comment https://forums.phpfreaks.com/topic/112295-how-can-i-fix-this-dynamic-table/#findComment-576563 Share on other sites More sharing options...
cooldude832 Posted June 28, 2008 Share Posted June 28, 2008 why don't u use a proper where clause in your query to get the results you desire. Link to comment https://forums.phpfreaks.com/topic/112295-how-can-i-fix-this-dynamic-table/#findComment-576564 Share on other sites More sharing options...
kevy Posted June 28, 2008 Author Share Posted June 28, 2008 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? Link to comment https://forums.phpfreaks.com/topic/112295-how-can-i-fix-this-dynamic-table/#findComment-576776 Share on other sites More sharing options...
kevy Posted June 28, 2008 Author Share Posted June 28, 2008 why don't u use a proper where clause in your query to get the results you desire. I tried but can't get it to run error free and display results.. Feel like writing out what you suggest? Link to comment https://forums.phpfreaks.com/topic/112295-how-can-i-fix-this-dynamic-table/#findComment-576778 Share on other sites More sharing options...
kevy Posted June 29, 2008 Author Share Posted June 29, 2008 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> Link to comment https://forums.phpfreaks.com/topic/112295-how-can-i-fix-this-dynamic-table/#findComment-577061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.