Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 41
  • Last Modified:

PHP Help - URL make clickable

Hello, Experts,

I built a PHP script that queries a database and outputs the results in JS/HTML form. If you could review the code below, I need help how to make the result field URL clickable.

Example:

Name: John Doe
URL: http://google.com

When results display for John, he is able to see the result set for his name and click on http://google.com

Let me know if you need further clarification.

<?php
//fetch.php
$connect = stuff
$output = '';
if(isset($_POST["query"]))
{
 $search = mysqli_real_escape_string($connect, $_POST["query"]);
 $query = "
  SELECT * FROM emp_details 
  WHERE dept LIKE '%".$search."%'
  OR fname LIKE '%".$search."%' 
  OR lname LIKE '%".$search."%' 
  OR pkid LIKE '%".$search."%' 
  OR url LIKE '%".$search."%'
 ";
}
else
{
 $query = "
  SELECT * FROM emp_details;
 ";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
 $output .= '
  <div class="table-responsive">
   <table class="table table bordered">
    <tr>
     <th>pkid</th>
     <th>fname</th>
     <th>lname</th>
     <th>department Code</th>
     <th>url</th>
    </tr>
 ';
 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["pkid"].'</td>
    <td>'.$row["fname"].'</td>
    <td>'.$row["lname"].'</td>
    <td>'.$row["DEPT"].'</td>
    <td>'.$row["url"].'</td>
   </tr>
  ';
 }
 echo $output;
}
else
{
 echo 'Data Not Found';
}

?>

Open in new window

0
sj77
Asked:
sj77
1 Solution
 
Sam WallisCommented:
simply changing line 45 to
<td><a href="'.$row["url"].'">'.$row["url"].'</a></td>

Open in new window

should do it
0
 
HainKurtSr. System AnalystCommented:
my suggestion

<tr onclick="window.location.href='.$row["url"].'" style="cursot:pointer">
    <td>'.$row["pkid"].'</td>
    <td>'.$row["fname"].'</td>
    <td>'.$row["lname"].'</td>
    <td>'.$row["DEPT"].'</td>
    <td>'.$row["url"].'</td>
   </tr>

Open in new window


you can click to anydata...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now