Jump to content


Photo

displaying hyperlinks in table stored in database [RESOLVED] and fast


  • Please log in to reply
2 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 17 August 2006 - 02:35 PM

I am trying to display sponsors hyperlinks that is stored in MySQL in a table column.

I can display them if I'm just echoing the database but if i try and put anchor tags around the hyperlink it displays nothing

This code will work
$q = mysql_query("SELECT * FROM `sponsors` ORDER BY name ASC LIMIT $set_limit, $limit"); 
  if(!$q) die(mysql_error()); 
     $err = mysql_num_rows($q); 
       if($err == 0) die("No matches met your criteria."); 
$numofrows = mysql_num_rows($q);

//Results per page: **EDIT LINK PATH**  

//show data matching query: 
echo "<table border=\"0\">\n";
echo "<tr bgcolor=\"lightblue\"><th width=\"200\">Name</th><th width=\"140\">Location</th><th width=\"300\">URL</th></tr>\n";
for($i = 0; $i < $numofrows; $i++) {
    $row = mysql_fetch_array($q); //get a row from our result set
    if($i % 2) { //this means if there is a remainder
        echo "<tr bgcolor=\"yellow\">\n";
    } else { //if there isn't a remainder we will do the else
        echo "<tr bgcolor=\"white\">\n";
    }
    echo "<td>".$row['name']."</td><td>".$row['location']."</td><td>".$row['url']."</td>\n";
    echo "</tr>\n";
}
//now let's close the table and be done with it
echo "</table>\n";
Unless i change this
echo "<td>".$row['name']."</td><td>".$row['location']."</td><td>".$row['url']."</td>\n";
to this
echo "<td>".$row['name']."</td><td>".$row['location']."</td><td><a href='".$row['url']."'</a></td>\n";
I know there is something dodgey about the anchor link but i can't put my finger on it
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 02:37 PM

Try...

echo "<td>".$row['name']."</td><td>".$row['location']."</td><td><a href='".$row['url']."'>".$row['name']."</a></td>\n";


#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 17 August 2006 - 02:51 PM

Thanks Thorpe....worked a treat
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users