Page 1 of 1

simple code displaying hyperlink

Posted: Thu Dec 31, 2009 11:10 am
by cosmini
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&nbsp'.$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>');
}

}

Re: simple code displaying hyperlink

Posted: Thu Dec 31, 2009 11:27 am
by SimpleManWeb
Here's a really easy solution:

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>')}
 
}
 
Enjoy

Re: simple code displaying hyperlink

Posted: Thu Dec 31, 2009 12:43 pm
by cosmini
thanks a bunch !!! it worked like a charm ;-) (after a minor correction)