1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need advice on how to make a link ?

Discussion in 'PHP' started by Amilo, May 3, 2008.

  1. #1
    I have a database that contains a field that are links,I can display the url on the page but can anyone tell me how to make the link go to the url it points to when clicked? or even better a button that is clickable.

    This is my code:
    $data = mysql_query("SELECT * FROM mydatabase WHERE class LIKE'weather'");
    while($result = mysql_fetch_array( $data ))
    
    {
    echo $result['weather_today'];
    echo "<br>";
    echo $result['weather_next'];
    echo "<br>";
    echo $result['url'];
    echo "<br>";
    echo "<br>";
    
    }
    ?>
    Code (markup):
    Thank you...
     
    Amilo, May 3, 2008 IP
  2. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is this what you're looking for?
    
    $data 	= 	mysql_query("SELECT * FROM mydatabase WHERE class LIKE'weather'");
    while ($result = mysql_fetch_array($data)) {
    	echo($result['weather_today']);
    	echo("<br>");
    	echo($result['weather_next']);
    	echo("<br>");
    // the link?
    	echo("<a href='".$result['url']."' target='_blank'>".$result['url']."</a>");
    	echo("<br>");
    	echo("<br>");
    }
    ?>
    Code (markup):
     
    Altari, May 3, 2008 IP
  3. Amilo

    Amilo Peon

    Messages:
    624
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you Altari thats great !
    This is the rubbish I had tried to write:
    echo "<a href=\"".$result."\" target=\"_blank\">url</a>";


    Do you know how to add a button for the link instead of text ?
     
    Amilo, May 3, 2008 IP
  4. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <a href='".$result['url']."' target='_blank'><img src='' /></a>

    Pm me if you need help
     
    NatalicWolf, May 3, 2008 IP
  5. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Like a submit button?

    You could do
    echo("<a href='".$result['url']."' target='_blank'><input type='submit' value='Go To Teh Link' /></a>");
    Code (markup):
    Or you could do as suggested by Natalic, to use any image
    echo("<a href='".$result['url']."' target='_blank'><img src='LINK TO IMAGE' alt='SOME ALT TEXT' /></a>");
    Code (markup):
     
    Altari, May 3, 2008 IP