Page 1 of 1

getting mysql stored url's to show as hyperlinks in a table

Posted: Tue Apr 20, 2004 2:24 pm
by emile
I have a mysql database of which one field contains lots of url's

I am trying to write php code to display the url's eg...

Product, details, Click Here (which is a hyperlink to http://www.... etc)

Here is the code I was using...

$count = 1;
print "table settings/columns/headings etc etc"
while ($row = mysql_fetch_assoc($r)) {
$data .= "<tr>";
$data .= "<td>" .$row['product']."</font>";
$data .= "<td>" .$row['details']."</font>";
$data .= "<td><a href=\".$row['url'].\">"Click here</a></font></td>";
$count++;
}
}
data .="<table>";
echo $data;

I know the method i am using is wrong, but for info here is the error message I get...

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

But does anyone know a work around for this ?

:?
Cheers

Posted: Tue Apr 20, 2004 2:48 pm
by Steveo31
What is the actual code...

Please use the php tags too.

Posted: Tue Apr 20, 2004 2:59 pm
by emile
<html>
headers n stuff
<body>
other stuff

<?php

$db_host = "blank";
$username = "blank";
$password = "hmm let me think... yes blank!";
$DB_name = "blank";
$table = "table";

$chan = mysql_connect ($db_host, $username, $password);
mysql_select_db ($DB_name, $chan);
$sql = "SELECT product, details, url FROM $table ORDER BY id";

if (!$r = mysql_query($sql))

{

die('Query Error: ' . mysql_error());

}

if (mysql_num_rows($r) == 0)

{

die('Query returned 0 results!');

}

else

{

$count = 1;

print "<table> properties, header columns etc etc "
while ($row = mysql_fetch_assoc($r)) {

$data .= "<tr>";

$data .= "<td>" .$row['product']."</font>";
$data .= "<td>" .$row['details']."</font>";
$data .= "<td><a href=\".$row['url'].\">"Click Here</a></font></td>";

$count++;

}

}

$data .="<table>";
echo $data;
?>
footers n stuff
</body>
</html>

Posted: Tue Apr 20, 2004 3:59 pm
by xisle
try ...
while ($row = mysql_fetch_array($r))

Posted: Tue Apr 20, 2004 4:09 pm
by feyd

Code: Select all

$data .= "<td><a href=".$row['url'].">"Click here</a></font></td>";
I believe that's the actual problem. You're escaping the quote marks, so .$row['url']. is considered part of the string. switching it to $row[url] will fix that.

Additionally:

Code: Select all

print "&lt;table&gt; properties, header columns etc etc "
needs a semicolon (;) after it.

Sidenote: you're not ending your table rows.

Posted: Tue Apr 20, 2004 4:17 pm
by emile
Still get error message...

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

on the following line...

$data .= "<td><a href=\".$row['url'].\">Click Here</a></font></td>";



Is it because the .$row['url']. can't be used within quotes "<td> etc etc </td> " on that line?

Posted: Tue Apr 20, 2004 5:29 pm
by feyd
it can.. but you are escaping the quotes just around it.. here's one that uses quotes:

Code: Select all

$data .= "<td><a href="".$row&#1111;'url']."">"Click here</a></font></td>";