Jump to content


Photo

Syntax for displaying query results as hyperlink.


  • Please log in to reply
5 replies to this topic

#1 mank1

mank1
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 15 July 2006 - 01:35 PM

Here's the code:

<?php
$con = mysql_connect("host","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("theDB", $con);

$result = mysql_query("SELECT * FROM theTable");

while($row = mysql_fetch_array($result))
  {
  //$site = $row['siteName'];
  //$url = $row['siteURL'];
  //echo "<a href='$url'>$site[/url]";
  echo $row['siteName'] . " " . $row['siteURL'];
  echo "<br />";
  }
mysql_close($con);
?>

As is, the script returns, for example:
Adobe http://www.adobe.com

As you've already guessed, my problem is with the three lines that are currently commented out.
What is the proper syntax for the echo <a> tag?
Running : Apache 2.2.2, PHP 5.1.4, MySQL 5.0.22 on Windows XP Home SP2

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 15 July 2006 - 01:44 PM

try this, replace the 3 lines commented out with these:

$site = $row['siteName'];
$url = $row['siteURL'];
echo "<a href=\"$url\">$site</a>";

Life's too short for arguing.

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 15 July 2006 - 01:46 PM

echo "<a href='". $row['siteURL']. "'>". $row['siteName']. "</a><br/>";

Legend has it that reading the manual never killed anyone.
My site

#4 mank1

mank1
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 15 July 2006 - 02:11 PM

Thanks.

echo "<a href=\"$url\">$site[/url]";
Returned a blank page. It looks like it should work, and now I'm curious why it doesn't.
Did I mis-type something?

echo "<a href='". $row['siteURL']. "'>". $row['siteName']. "</a><br />";
Returned a list hyperlinks. Right on.

I should've posted this yesterday. All the countless hours wasted.

Thanks again.
Running : Apache 2.2.2, PHP 5.1.4, MySQL 5.0.22 on Windows XP Home SP2

#5 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 15 July 2006 - 02:27 PM

this message board some how, changed  </a> to [/url]

I had to put the comment inside a code block.  hmmm
Life's too short for arguing.

#6 mank1

mank1
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 15 July 2006 - 02:54 PM

Actually, that was what I originally posted.
I, too, now see the purpose of using the Insert Code feature, though.

Anyway, I tested your modified example, and it works. Thanks.
Running : Apache 2.2.2, PHP 5.1.4, MySQL 5.0.22 on Windows XP Home SP2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users