/    Sign up×
Community /Pin to ProfileBookmark

Suggesting for Managing Links

I want to use PHP and perhaps a DB to manage all the hpyerlinks on my site… What would be the best way to do the following:

Link 1, Link 5, Link 7, Link 6 I want to display onpage1.php

Link 1, Link 2, Link 3, Link 8, Link 9 I want to display on page2.php and so on.

I want this so that I can track the links and easily add a link to multiple pages at one time. All suggestions are appreciated.

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 24.2006 — Use a template and add the links to the template. An example of this would be a navigation menu which would be held in a file and included on all pages. Is this what you meant?
Copy linkTweet thisAlerts:
@firmanauthorJul 24.2006 — yes and no.... I understand that.. but say Link 1 is on page1.php and page2.php.... I want to be able to go to one place... change Link1 and have it change everywhere.
Copy linkTweet thisAlerts:
@The_Little_GuyJul 24.2006 — you could place each link in a switch statement in its own file, and include the links that you want from that file.
Copy linkTweet thisAlerts:
@firmanauthorJul 24.2006 — Can you explain a lil further TLG?
Copy linkTweet thisAlerts:
@The_Little_GuyJul 24.2006 — What I was saying is do something like this:

[B]links.php[/B]
[code=php]<?
switch($links){
case 1:
echo'<a href="http://google.com">Google</a>';
break;
case 2:
echo'<a href="http://yahoo.com">Yahoo</a>';
break;
case 3:
echo'<a href="http://altavista.com">Altavista</a>';
break;
case 4:
echo'<a href="http://search.d-top.org">Finder</a>';
break;
}
?>[/code]

[B]

page1.php[/B]

[code=php]<?
include('links.php?links=1');
echo"<br>";
include('links.php?links=2');
echo"<br>";
include('links.php?links=3');
echo"<br>";
include('links.php?links=4');
?>[/code]


The only problem is, I can't get it to work, I keep getting an error:

[B]Warning[/B]: main(links.php?links=1): failed to open stream: No such file or directory in [B]/home2/dtoporg/public_html/a/thispage.php[/B] on line [B]2[/B]

[B]Warning[/B]: main(): Failed opening 'links.php?links=1' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in [B]/home2/dtoporg/public_html/a/thispage.php[/B] on line [B]2[/B]
Copy linkTweet thisAlerts:
@bokehJul 24.2006 — yes and no.... I understand that.. but say Link 1 is on page1.php and page2.php.... I want to be able to go to one place... change Link1 and have it change everywhere.[/QUOTE]That is what an include does.
Copy linkTweet thisAlerts:
@firmanauthorJul 24.2006 — and if I delete a link.. Would it error out or jsut skip it?
Copy linkTweet thisAlerts:
@The_Little_GuyJul 24.2006 — actually I thought of a better way!!!

make a file with your links, as variables like this:

[B]

links.php[/B]

[code=php]<?
$link1 = '<a href="http://google.com">Google</a>';
$link2 = '<a href="http://yahoo.com">Yahoo</a>';
$link3 = '<a href="http://altavista.com">Altavista</a>';
$link4 = '<a href="http://search.d-top.org">Finder</a>';
?>[/code]


next make a page, and include links.php, then echo out each link you want displayed.

[B]page1.php[/B]
[code=php]<?
include('links.php');

echo"$link1";
echo"<br>";
echo"$link4";
?>[/code]


This is the same as page1.php only with different links.

[B]page2.php[/B]
[code=php]<?
include('links.php');

echo"$link1";
echo"<br>";
echo"$link2";
echo"<br>";
echo"$link3";
?>[/code]
Copy linkTweet thisAlerts:
@bokehJul 24.2006 — actually I thought of a better way!!![/QUOTE]That's bad news. It means that deleting a link involves editing multiple files which the OP was trying to avoid in the first place. Easiest way is put the links in a file:[code=html]<a href="http://google.com">Google</a>
<a href="http://yahoo.com">Yahoo</a>
<a href="http://altavista.com">Altavista</a>
<a href="http://search.d-top.org">Finder</a>[/code]
and [I]include()[/I] the file. The example is a crude but should give the general idea.
Copy linkTweet thisAlerts:
@firmanauthorJul 24.2006 — Thank you everyone!!... You just gave me a few great ideas for my site.
Copy linkTweet thisAlerts:
@The_Little_GuyJul 24.2006 — That's bad news. It means that deleting a link involves editing multiple files which the OP was trying to avoid in the first place. Easiest way is put the links in a file:[code=html]<a href="http://google.com">Google</a>
<a href="http://yahoo.com">Yahoo</a>
<a href="http://altavista.com">Altavista</a>
<a href="http://search.d-top.org">Finder</a>[/code]
and [I]include()[/I] the file. The example is a crude but should give the general idea.[/QUOTE]

That is what I did
Copy linkTweet thisAlerts:
@bokehJul 24.2006 — That is what I did[/QUOTE]Not quite... You are assigning variables which means you cant just delete a link out of the included file.
×

Success!

Help @firman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...