Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.