...

View Full Version : Storing links in mysql and displaying them with PHP



jedimastermopar
12-19-2006, 06:37 PM
I am sure this has been asked but I am having problems storing links. I have a feeling like you can't just store for example,
<a href="http://XXX.XXX.XXX.XXX/jobpostings/internal/FldTechnicianGeotechnical.pdf">Field Tech </a>

in a job posting table, under the url field and just properly display the link?

Crimsonjade
12-19-2006, 06:58 PM
I assume you are storing the link in some variable like this:



$my_url = '<a href="http://XXX.XXX.XXX.XXX/jobpostings/internal/FldTechnicianGeotechnical.pdf">Field Tech </a>';


What is the problem with sticking that in a database?

Brandoe85
12-19-2006, 07:55 PM
Don't store the html, just store the URL or the path and build up your <a> when you run your query.

good luck;

Crimsonjade
12-19-2006, 08:51 PM
Right, the html is redundant. You are better off making two fields within a table: url_path and url_name and using the method brandoe suggested.

Linark
12-19-2006, 09:14 PM
Use something like this:


$query = "SELECT url, name FROM the_links";

mysql_query($query);

$the_links = "";

while ( $r = mysql_fetch_assoc() ) {

$the_links .= "<a href='{$r['url']}'>{$r['name']}</a><br />\n";

}

echo $the_links;

The above code has NOT been tested, but it should work if you just add the mysql connection part to the begining.

Tyree
12-19-2006, 09:20 PM
The above code has NOT been tested, but it should work if you just add the mysql connection part to the begining.


Well, just so you make sure all the var names are the same.
$the_link, $the_links, and $links should all be the same variable. ;)

Linark
12-20-2006, 07:18 AM
Well, just so you make sure all the var names are the same.
$the_link, $the_links, and $links should all be the same variable. ;)

I know! lol!

Don't you just love typos!

The code sample has been updated to reflect this typo mistake.

Tyree
12-20-2006, 11:50 AM
Heh heh...happens to the best of us (and me too)! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum