Jump to content

Dynamic menu


NLCJ

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/189624-dynamic-menu/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/189624-dynamic-menu/#findComment-1000809
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/189624-dynamic-menu/#findComment-1000829
Share on other sites

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.