PHP\MySQL linking to name on page

This may be hard for me to explain as I am not well versed in these terms just yet but here goes.

I am working on a church website for my church. In this website is a page with a list of ministries on it. They want it dynamic and have a CMS backend for it so they can add/edit/delete them as they need to. This is no problem, I have it in the DB and outputting to the page, the problem lies with the side menu for it. The side menu just has that same list of ministries in it, and when a link is clicked just takes you down the page to the selected ministry. But when I output the ministries on the page from the DB I do not know how to make that continue to work. So if I clicked on the ‘bus ministry link’:

[code]

[/code]

It would go to here on the page:

[code]



Bus Ministry

Every week we transport children and adults to church where they are shown God's love and taught His Word.

Back to Top

[/code]

But now that I am outputting through PHP from a DB I cannot figure out how to implement that. Here is my output code:

[php]<?php $query=“SELECT * FROM ministries“;
$resource=mysql_query($query);
while($result=mysql_fetch_array($resource))
{
echo “”.$result[‘name’].”

”.$result[‘ministry’]."

<div class=“content_box”> ";
}
?>[/php]

I hope this is not too much of me to ask, but I had to try :slight_smile: I thank you guys for your time and help with everything so far, as well.

I’m not sure if I understand the problem. When you do your echo, shouldn’t it include the anchor?

[php]
echo “<a name=“bus”>”.$result[‘name’]."

".$result[‘ministry’]."

<div class=“content_box”> ";
[/php]

Only problem with that is, the while loop will echo out all the entries into the database. So if I echoed the achor of ‘bus’ then only the bus link in the menu would be working. Im sure there is a simple way to do this I just cannot seem to figure it out.

Thank you for replying though, sir.

Well, of course you would need to specify a unique identifier for each one. You could either add a new column to the table or use the existing ‘name’ field.

[php]
echo “<a name=”" . $result[‘name’] . “”>".$result[‘name’]."

".$result[‘ministry’]."

<div class=“content_box”> ";
[/php]

Then the menu would have to match this.

[php]
echo “

  • <a href=”#" . $result[‘name’] . “”>" . $result[‘name’] . “
  • ”;
    [/php]

    Works like a charm. Thank you very much, sir. :slight_smile:

    Sponsor our Newsletter | Privacy Policy | Terms of Service