0

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);

2 Answers 2

2

In its simplest form:

<a href="<?php echo $URL;?>">CLICK</a>
Sign up to request clarification or add additional context in comments.

3 Comments

That about sums it up
Thanks Ironcito. Do I put this within the <td> </td> table area. Sorry pretty new to all of this
I don't know exactly how you want to do it. If the URL is a field in the database, then you could add a line like @Vacation9 said, changing the name of the field if necessary.
0

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.

1 Comment

Just tried it out. Worked perfectly first time. Thanks again Vacation9 and Ironcito

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.