Reputation: 379
I would like to extract URL's from a mysql database. However I wish to link the URL to a single word 'CLICK' in a table.
The snippet of code below extracts data from a mysql database and puts it in a table as a series of rows. For each row there is a respective URL which I also wish to extract from the database. Instead of showing the full and long URL I just want to have the word CLICK against each row which people can then click to access that URL. Can any body tell me how that is done?
$q="SELECT * FROM railstp WHERE DOWNLOAD='$changeday'";
$r=mysqli_query($mysql_link,$q);
if ($r)
{
echo "<strong>Network Rail Schedule (STP) updates downloaded: $changeday</strong>";
echo "<p> </p>";
echo "<Table id='customers'>
<tr>
<th>Headcode</th>
<th>Traction</th>
<th>From</th>
<th>To</th>
<th>Departing</th>
<th>Destination</th>
<th>Depart</th>
<th>Arrive</th>
<th>ATOC</th>
<th>Runs</th>
<th>Load</th>
<th>Speed</th>
</tr>";
while ($row=mysqli_fetch_array($r,MYSQLI_ASSOC))
{
echo "<tr>";
echo "<td>".$row['HEADCODE']."</td>";
echo "<td>".$row['TRACTION']."</td>";
echo "<td>".$row['STARTDATE']."</td>";
echo "<td>".$row['ENDDATE']."</td>";
echo "<td>".$row['DEPART']."</td>";
echo "<td>".$row['ARRIVE']."</td>";
echo "<td>".$row['DEPARTTIME']."</td>";
echo "<td>".$row['ARRIVALTIME']."</td>";
echo "<td>".$row['ATOC']."</td>";
echo "<td>".$row['RUNS']."</td>";
echo "<td>".$row['LOAD']."</td>";
echo "<td>".$row['SPEED']."</td>";
echo "</tr>";
}
echo "</Table>";
}
else {echo '<p>'.mysqli_error($mysql_link).'</p>' ;}
}
show_records($mysql_link);
mysqli_close($mysql_link);
Upvotes: 0
Views: 1237
Reputation: 628
Add this to your row code:
echo "<td><a href='".$row['URL']."'>CLICK</a></td>";
What this does is add the URL as the parameter to the link but as the link text only show CLICK. Replace URL with the column name for your url.
Upvotes: 0