I am new to php (sorry). I cannot figure out how to make 'field_4' below display as a click-able URL. It is stored in my mysql db in a varchar field.

Any help would be great, thanks.

$result = mysql_query("SELECT * FROM units ORDER BY `field_1`, `field_2`");

echo "<table width='940' cellpadding='3' cellspacing='4' border='0'>
<th width='5' align='right'>Unit</th>
<th width='290' align='left'>Designation</th>
<th width='350' align='left'>Unit Information</th>
<th width='' align='left'>Website</th>

while($row = mysql_fetch_array($result))
  echo "<tr>";
  echo "<td align='right' valign='top'>" . $row['field_1'] . "</td>";
  echo "<td valign='top'>" . $row['field_2'] . "</td>";
  echo "<td valign='top'>" . $row['field_3'] . "</td>";
  echo "<td valign='top'>" . $row['field_4'] . "</td>";
  echo "</tr>";
echo "</table>";

Recommended Answers

All 5 Replies

Just the same as in any html file, wrap it in

<a href=""></a>

Assuming field_4 is the url line 18 would be :

echo "<td valign='top'><a href=\"" . $row['field_4'] . "\">the anchor text you want to use</a></td>";

, though personally I prefer:

echo "<td valign='top'><a href=\"{$row['field_4']}\">the anchor text you want to use</a></td>";

as I find it a lot easier to read and debug.

use urlencode and urldecode to display data as url

for field_2 , url will be, echo $row['field_2'] ." "." <a href= 'abc.php?field=" . urlencode( $row['field_2'] ) . "'>Click Here</a>"; now create another page and call it 'abc.php'
and decode the url in it,

$link = urldecode( $_GET['field'] );
echo "<center><h1>" . $link . "</h1></center>";

similarly, repeat this for other fields

Thanks all this helped a lot! My end result now looks like this page at http://www.f-101voodoo.com/voodoo_squadrons.php

The only thing I'm not crazy about is that every line entry has a link, but not every record has a url data entry in field_4. The link that displays for those records just links back to this same page by default.

Is there a way to not show a link if there is no data available in that database field?

But, this is great! You have helped me a ton, thanks

Sure, add an if statement:

if ($row['field_4'] != "") {
  echo "<td valign='top'><a href=\"" . $row['field_4'] . "\">the anchor text you want to use</a></td>";
  else {
  //whatever you want to do where there isn't a url

Fantastic! Thanks tiggsy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.