NLCJ Posted January 24, 2010 Share Posted January 24, 2010 Hello, I am creating a website, and I was trying to create a dynamic menu by using MySQL. So it would be easier to manage, through an Admin panel you can insert information in MySQL and the dynamic menu will take it out like this: $d_getlinks = "SELECT * FROM paginas"; $d_links = mysql_fetch_array(); <div class="menu"> <a href="<?php echo $d_links['link']; ?>"><?php echo $d_links['menu']; ?></a> </div> This gives the result I wanted except that it only gives the first value, how can I get it to display ALL the links in that table? Regards, Chris Quote Link to comment https://forums.phpfreaks.com/topic/189624-dynamic-menu/ Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2010 Share Posted January 24, 2010 This is more a PHP issue as your MySQL is fine. You need to create a loop, like so: <div class="menu"> <?php $d_getlinks = "SELECT * FROM paginas"; while($d_links = mysql_fetch_array()) { ?> <a href="<?php echo $d_links['link']; ?>"><?php echo $d_links['menu']; ?></a> <?php } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/189624-dynamic-menu/#findComment-1000809 Share on other sites More sharing options...
NLCJ Posted January 24, 2010 Author Share Posted January 24, 2010 Now it only shows the second value. Thank you though for answering, one step closer to the solution! EDIT: It shows all except the first one... :S Quote Link to comment https://forums.phpfreaks.com/topic/189624-dynamic-menu/#findComment-1000824 Share on other sites More sharing options...
PHP Monkeh Posted January 24, 2010 Share Posted January 24, 2010 I'm hopeless, sorry. Try this: <div class="menu"> <?php $d_getlinks = "SELECT * FROM paginas"; $d_result = mysql_query($d_getlinks); while($d_links = mysql_fetch_array($d_result)) { ?> <a href="<?php echo $d_links['link']; ?>"><?php echo $d_links['menu']; ?></a> <?php } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/189624-dynamic-menu/#findComment-1000829 Share on other sites More sharing options...
NLCJ Posted January 24, 2010 Author Share Posted January 24, 2010 Thank you very much, it's working! Quote Link to comment https://forums.phpfreaks.com/topic/189624-dynamic-menu/#findComment-1000834 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.