0

I am trying to display a link in a php document. the data is stored in mysql. I have stored the url in the field course_url.

i can get the page to show the hyperlink asd a plain text but want it to show ashyperlink with "Click Here" anchor text. The coding i got so far is:

 <?php
$con=mysqli_connect("localhost","root","","mentertraining");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


$query = "SELECT `coursedates`.`coursedate_id`,`coursedates`.`course_id`,`coursedates`.`date1`,`courses`.`course_title`,`courses`.`course_url`,`courses`.`no_of_days` FROM coursedates\n"
    . "LEFT JOIN `mentertraining`.`courses` ON `coursedates`.`course_id` = `courses`.`course_id` LIMIT 0, 30 ";

$result = mysqli_query($con,$query);
    echo "<table border='1'><tr><th>Course Title</th><th>Course Date</th><th>No of Days</th><th>Course URL</th></tr>";

while($row    = mysqli_fetch_assoc($result))
  {
  $date = new DateTime($row['date1']);
    $row['date1'] = $date->format('d/m/Y');

  echo "<tr>";
  echo "<td>" . $row['course_title'] . "</td>";
   echo "<td>" . $row['date1'] . "</td>";
    echo "<td>" . $row['no_of_days'] . "</td>";
  echo "<td>""<a href=" . $row['course_url'] .  >"'Click Her'"</a>""</td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?> 
0

2 Answers 2

1

Your echo is malformed on this line:

echo "<td>""<a href=" . $row['course_url'] .  >"'Click Her'"</a>""</td>";

It should be:

echo "<td><a href='" . $row['course_url'] .  "'>Click Here</a></td>";
Sign up to request clarification or add additional context in comments.

Comments

0

You have used the wrong "' quotations

while($row    = mysqli_fetch_assoc($result))
  {
  $date = new DateTime($row['date1']);
    $row['date1'] = $date->format('d/m/Y');

  echo "<tr>";
  echo "<td>" . $row['course_title'] . "</td>";
   echo "<td>" . $row['date1'] . "</td>";
    echo "<td>" . $row['no_of_days'] . "</td>";
  echo "<td><a href='" . $row['course_url'] ."'>Click Her</a></td>";
  echo "</tr>";
  }

Comments

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.