Jump to content


Storing Hyperlinks in MySQL

  • Please log in to reply
1 reply to this topic

#1 hansman

  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 21 May 2006 - 05:39 PM

what type of field would i use to store " [a href=\"http://www.mydomain.com/\" target=\"_blank\"]http://www.mydomain.com/[/a] " in MySql
and how would i out put it as a link in PHP

thanks in advance for your help

#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 May 2006 - 06:17 PM

VARCHAR(255) will do for storing a hyperlink, it can store a maximun of 255 characters

now to get the hyperlink out of the database I'd use this:


//connect to database here

$sql = "SELECT hyperlink_col FROM table_name";
$result = mysql_query($sql);

while($row = myql_fetch_array($result))
    echo "<a href=\"" . $row['hyperlink_col'] . \">Link</a>";

Note, make sure you change hyperlink_col with the actual column name that stores the hyperlink and change table_name with the actuall name of the table you use that stores the hyperlink column in.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users