webtuto Posted January 9, 2008 Share Posted January 9, 2008 hi here im trying to post the outputs from the database in a <select> here is the code ---> <?php $query="select * from groups order by id"; $result=mysql_query($query); $row=mysql_fetch_array($result); $cat=$row[group]; ?> <option name="<?php echo $cat; ?>"><?php echo $cat; ?></option> <tr><td><input type="submit" value="Send" name="send"></tr> </select></tr> but it gives just 1 output from the table , i want it to list me all the results !!!! *!* Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/ Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Use a while loop Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434538 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 <?php $query="select * from groups order by id"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $cat=$row[group]; ?> <option name="<?php echo $cat; ?>"><?php echo $cat; ?></option> <tr><td><input type="submit" value="Send" name="send"></tr> </select></tr> <?php } ?> I think that will work Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434542 Share on other sites More sharing options...
webtuto Posted January 9, 2008 Author Share Posted January 9, 2008 no it didnt work and how to do that loop it tried but i failed Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434546 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 You want to put the OPTION tag in the while loop, but leave the SELECT and SUBMIT button out of it so it only gets placed once. Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434549 Share on other sites More sharing options...
Lumio Posted January 9, 2008 Share Posted January 9, 2008 <?php $query="select * from groups order by id"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $cat=$row[group]; ?> <option name="<?= $cat ?>"><?= $cat ?></option> <?php } ?> <tr><td><input type="submit" value="Send" name="send"></tr> </select></tr> Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434553 Share on other sites More sharing options...
webtuto Posted January 9, 2008 Author Share Posted January 9, 2008 thanks it works thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434555 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Should change <option name="<?= $cat ?>"><?= $cat ?></option> to <option name="<?php echo $cat ?>"><?php echo $cat ?></option> Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434557 Share on other sites More sharing options...
Lumio Posted January 9, 2008 Share Posted January 9, 2008 but use htmlentities() or htmspecialchars() for that category output. @revraz Why? <?= is nearly the same as <?php echo ... Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434561 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 If short tags are enabled, but too many posts here are solved just by telling them to use the full <?php So assume short tags support is off. @revraz Why? <?= is the same as <?php echo ... Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434564 Share on other sites More sharing options...
Lumio Posted January 9, 2008 Share Posted January 9, 2008 Oh... okay thx for that... I didn't know that Quote Link to comment https://forums.phpfreaks.com/topic/85172-plz-help-me-here/#findComment-434851 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.