Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Storing links in mysql and displaying them with PHP

    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?

  • #2
    New Coder
    Join Date
    Dec 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I assume you are storing the link in some variable like this:

    PHP Code:
    $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?

  • #3
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Don't store the html, just store the URL or the path and build up your <a> when you run your query.

    good luck;

  • #4
    New Coder
    Join Date
    Dec 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New Coder
    Join Date
    Nov 2006
    Location
    UK
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use something like this:

    Code:
    $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.
    Last edited by Linark; 12-20-2006 at 08:17 AM.
    - Mark

  • #6
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by Tyree; 12-19-2006 at 10:23 PM.
    Matt Tyree
    TyreeOnline
    If I didn't just "make it worse," show me some love! Hit me with the rep points! :) (The white scales icon on the left)

  • #7
    New Coder
    Join Date
    Nov 2006
    Location
    UK
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Tyree View Post
    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.
    - Mark

  • #8
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heh heh...happens to the best of us (and me too)!
    Matt Tyree
    TyreeOnline
    If I didn't just "make it worse," show me some love! Hit me with the rep points! :) (The white scales icon on the left)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •