hi all, I'm a complete PHP newbie and trying to get something basic working, basically, a hyperlink, if a field name is 'LINK'
here's the original script, to be modified towards the bottom
thx much for any help.
Cos
if($num_row >0)
{
//Get number of fields in query
$num_fields=mysql_num_fields($result);
# get column metadata
$i = 0;
//Set table width 15% for each column
$width=15 * $num_fields;
print('<br><table width='.$width.'% align="center"><tr>');
print('<tr><th colspan='.$num_fields.'>View '.$table.'</th></tr>');
while ($i < $num_fields)
{
//Get fields (columns) names
$meta = mysql_fetch_field($result);
$fields_array[]=$meta->name;
//Display column headers in upper case
print('<th><b>'.strtoupper($fields_array[$i]).'</b></th>');
$i=$i+1;
}
print('</tr>');
//Get values for each row and column
while($row=mysql_fetch_row($result))
{
print('<tr>');
for($i=0; $i<$num_fields; $i++)
{
//Display values for each row and column, however display hyperlink if table field name is 'LINK'
// <a href="http://www.website.com/repository/file.mp3">file.mp3</a>
if(strtoupper($fields_array[$i])='LINK')
{print('<td><a href="http://www.website.com/repository/'.$row[$i].'</td>')}
else
{print('<td>'.$row[$i].'</td>')}
}
print('</tr>');
}
}
simple code displaying hyperlink
Moderator: General Moderators
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: simple code displaying hyperlink
Here's a really easy solution:
Enjoy
Code: Select all
if(strtoupper($fields_array[$i])='LINK') {
?>
<td>
<a href="http://www.website.com/repository/<?php echo $row[$i] ?>">LINK</a>
</td>
<?php
} else {
print('<td>'.$row[$i].'</td>')}
}
Re: simple code displaying hyperlink
thanks a bunch !!! it worked like a charm
(after a minor correction)