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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post

    pulling info from db and outputting separate lines

    Input is from textbox and there is ONE URL per line in the textbox (sometimes it's just one url and other times it could be 50 urls). Input goes into mysql db (links)

    So my problem:
    Example: If I input three lines
    one.com
    two.com
    three.com
    The output of the code below would be:
    Link: one.com
    two.com
    three.com
    And they are NOT linked. Can anyone explain this? I'm probably not supposed to be using foreach, no?
    PHP Code:
    $result mysql_query("SELECT * FROM links WHERE callsign='$callsign1'");
    $row mysql_fetch_array($result);
    $linksfoo1 nl2br($row['links']);
    $linksfoo = array($linksfoo1);
    foreach (
    $linksfoo as $linksfoo) {
        echo 
    "Link: <a href=\"$linksfoo?\">$linksfoo</a>\n";

    <3 CF

  • #2
    New Coder
    Join Date
    Oct 2007
    Location
    Irwin, PA
    Posts
    23
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I would try to attempt using string replace and adding a simple HTML break tag at the end in an array. Try this:

    PHP Code:
    <?php
    $result 
    mysql_query("SELECT * FROM links WHERE callsign='$callsign1'");
    while(
    $rows=mysql_fetch_array($result)) {

    //add a closing to the anchor tag and a break tag after any findings of .com
    $break_link str_replace('.com''.com</a><br />'$rows['links']);

    //output your results
    echo '<a href="' .$rows['links']. '">' .$break_link'';

    }

    ?>
    In the above example, for each link in the main mysql array, if it has .com in the end, the string replace will add </a><br /> at the end of it, and then I print all those results. I set the variable $break_line equal to the string replace because it allows you to still use the $row['links'] for when using the anchor tag link, <a href="'. $rows['link']. '">

    Of course, this would force you to have to have .com at the end of each URL, but in that case, if you were using other domains, you could add those into an array and parse it through it like so:
    PHP Code:
    <?php
    $result 
    mysql_query("SELECT * FROM links WHERE callsign='$callsign1'");
    while(
    $rows=mysql_fetch_array($result)) {


    //in this one, we extend it to domains beyond ones with .com
    //not 100% sure this will work either but you can try it if you are using
    //more than just .com names
    $links = array('.com''.net''.biz''.org''.gov');
    $break_link str_replace('$links''$links</a><br />'$rows['links']);

    //output your results
    echo '<a href="' .$rows['links']. '">' .$break_link'';

    }

    ?>
    Let me know if I found a solution to your problem!

    WAIT, I just noticed I forgot to add the name of the link you are echoing, I'm sure you can add that (it's only going to print .com<br /> .com<br />) I'm sure you can fix that! Just make another string replace to take out the .com to print the plain text, then put the break_link string replace. I can't imagine it being much harder, let me know if it works or not though. I have found alot of good uses from str_replace function. Hmm, I'm not sure if you will need to edit it or not.
    Well, try it out. If only prints .com<br /> then it might be goofed up, but I think it's good, as the whole link like, three.com<br /> is being set equal to the break_link variable. Sorry, I'm kinda tired to get it right or not.
    Last edited by the game hog; 02-23-2008 at 07:18 AM.

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    That doesn't seem to work because it's only recognizing the last "domain.com".

    If it is in the db as
    "link1.com
    link2.com
    link3.com"
    I need to know how to handle each of those lines individually (really I just need to make them link accordingly)
    <3 CF

  • #4
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    Developed my own solution after reading up for a few hours.

    PHP Code:
    $result mysql_query("SELECT * FROM links WHERE callsign='$callsign1'");
    $row mysql_fetch_array($result);
    $links $row['links'];
    $chunks spliti ("
    "
    $links10);
    //print_r($chunks);
    foreach ($chunks as $value) {
        echo 
    "Link: <a target=\"_blank\" href=\"$value\">$value</a><br>";

    <3 CF


  •  

    Posting Permissions

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