tags:

views:

89

answers:

4

I have been working on trying to teach myself programming and have come stuck on a simple problem ,

the line I am working with is

echo "<td>" . $row['website'] . "</td>";

only in the database {mysql} it is in plain text under the column 'website' , I have been trying to work out how to make the row website clickable for the whole table,

i have tried  <href ="echo "<td>" . $row['website'] . "</td>""; 

I have tried searching the web for an answer , only i dont seem to be able to phrase the question for the right results.

thank you .


I also tried

<?
$result = mysql_query("SELECT * FROM leader");
echo "<table border='1'> <tr> <th>id</th> <th>Club</th> <th>Website</th> <th>Club Badge</th> </tr>";
while($row = mysql_fetch_array($result)) {
    echo "<tr>"."<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['club'] . "</td>";
    echo "<td>" . $row['website' ] . "</td>";
    echo "<td><a class=\"mylink\" href=\"" . $row['website'] . "\">" . $row['website'] . "</a></td>";
    echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>

but still got Parse error: syntax error, unexpected '<' in /home/a6332763/public_html/res.php on line 29

UPDATE......... Have now got link to show in right box only its adding the sites url in-front of the links url, here is the code , minus mysqul connection .

    <?php


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

echo "<table border='1'>
<tr>
<th>id</th>
<th>Club</th>
<th>Website</th>
<th>Club Badge Url</th>
</tr>";

while($row = mysql_fetch_array($result))

  {
  echo "<tr>"."<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['club'] . "</td>";



echo "<td><a class=\"mylink\" href=\"" . $row['website'] . "\">" . $row['website'] . "</a></td>";


 echo "</tr>";
  }
echo "</table>";




mysql_close($con);
?> 
<html>
<body>
<a href="res.php">Link text</a> 
Click on <a href="http://www.sumsitehere.com"&gt;this link</a> to run your first PHP script. 
</body>
</html>
A: 

Fill the appropriate onclick attribute with JavaScript code to open the new location.

Ignacio Vazquez-Abrams
While technically correct, that's not likely to be much help to someone that's new at this.
bemace
Thanks Ignacio Vazquez-Abrams , wots JavaScript ? {lol} an 'onclick` popup formatting thinggy would be helpful only dont get them with notepad.
simples
+2  A: 

Anchor tags (<a>) cannot contain table rows or cells. To make the entire row clickable, you must bind an onclick handler with JavaScript or wrap the contents of each individual <td> element with its own <a> tag.

meagar
+1  A: 

Hi,

If what you are looking for is a way to make a link out the area of the row where your links is do the following:

In the PHP file:

echo "<td><a class=\"mylink\" href=\"" . $row['website'] . "\">" . $row['website'] . "</a></td>";

In the CSS file:

.mylink{display:block;}

That should do it.

redhatlab
This is going to result in a tag with no content, and no `</a>`.
meagar
@meagar: I corrected the code. Thank you for the heads up.
redhatlab
thanks redhatlab, not got to CSS yet , understand that it controls all the sites formatting and could be very helpful and save loads of time later on.
simples
have made a .css file called CSS.css and have tried the above , am now getting `website` in one box {unclickable} and then again in the next column under a different heading { yet its clickable only it now adds the site url its on and the url of where to go to [eg http://mysite.net/www.yahoo.com thus results in a no go link] and the data that's spouse to be in that column is nowhere to be seen.
simples
` needed to delete a line of text has stopped the extra box.
simples
Why not just use single quotes within the string instead of escaped double quotes? Also, since the point of double quote strings in PHP is variable substitution, use the {} syntax instead of breaking the string to concatenate. For example `echo "<a class='mylink' href='{$row['website']}'>";`
Alex JL
A: 

If you just want the a regular link inside a table cell what you want is

<td><a href="<?= $row['website'] ?>"><?= $row['website'] ?></a></td>

If you were actually trying to make the entire table row clickable, you need to use a javascript redirect set on the table row:

<tr onClick="window.location='<?= $row['website'] ?>'">
    <td><?= $row['website'] ?></td>
</tr>
bemace
I will recommend you to use the full tag for php. Use <?php instead of just <?.
redhatlab
@redhatlab - You have fun typing that out every time then. Some of us have better things to do.
bemace
I have tried the above line as a straight copy n paste and also including echo before and with ; and sum extra " get the same sort of error *** Parse error: syntax error, unexpected '<' in /home/a6332763/public_html/res.php on line 29 ***
simples
@simples - it's hard to say what the problem would be without seeing the code around it
bemace
$result = mysql_query("SELECT * FROM leader");echo "<table border='1'><tr><th>id</th><th>Club</th><th>Website</th><th>Club Badge</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"."<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['club'] . "</td>"; echo "<td>" . $row['website' ] . "</td>"; echo "<td><a class=\"mylink\" href=\"" . $row['website'] . "\">" . $row['website'] . "</a></td>"; echo "</tr>"; }echo "</table>";mysql_close($con);?>
simples
@simples - it's really hard to read code in comments. I still don't see the source of the parse error. Try updating your question with the entire page's code if it's not too big.
bemace
@bemace there's no reason to assume that the server on which simples is working has short tags enabled. Many hosts do not enable short tags.
Alex JL
@Alex - simples is free to use whichever style he prefers, as is everyone else. I was just responding to be told how to write *my* code.
bemace
He can't use them if his host does not have short tags enabled in their php.ini. I'm not sure whether short_open_tags can be enabled at run time or not.
Alex JL