Jump to content

help with hyperlink


abas

Recommended Posts

Hello

Im making a select statement and the outputs are in a table but i want the entry of a column to be hyperlink to take to another page

 

thats a part of the code im using ..:

<?php
if (isset($_POST['search'])) {
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("drupal", $con);

$sql = "select uid , name , mail from users ";
$result = mysql_query($sql,$con);

if (($result)||(mysql_errno == 0))
{
  echo "<table width='100%'><tr>";
  
  if (mysql_num_rows($result)>0)
  {
          //loop thru the field names to print the correct headers
          $i = 0;
          while ($i < mysql_num_fields($result))
          {
       echo "<th>". mysql_field_name($result, $i) . "</th>";
       $i++;
    }
    echo "</tr>";
   
    //display the data
    while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
    {
      echo "<tr>";
      foreach ($rows as $data)
      {
  	
        echo "<td align='center'>" . $data . "</td>" ;
      }
    }
  }else{
    echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
  }
  echo "</table>";
}
else
{
  echo "Error in running query :". mysql_error();
}
}
?>

//i want the data of the name column to be hyperlink 

 

PLEASE ANY HELPPPPP

 

EDIT: Please use the [code][/code] tags!

Link to comment
https://forums.phpfreaks.com/topic/74285-help-with-hyperlink/
Share on other sites

Like so:

<?php
if (isset($_POST['search'])) {
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("drupal", $con);

$sql = "select uid , name , mail from users ";
$result = mysql_query($sql,$con);

if (($result)||(mysql_errno == 0))
{
  echo "<table width='100%'><tr>";
  
  if (mysql_num_rows($result)>0)
  {
          //loop thru the field names to print the correct headers
          $i = 0;
          while ($i < mysql_num_fields($result))
          {
       echo "<th>". mysql_field_name($result, $i) . "</th>";
       $i++;
    }
    echo "</tr>";
   
    //display the data
    while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
    {
      echo "<tr>";
      foreach ($rows as $data)
      {
  	
        echo "<td align='center'><a href='path/to/destination'>" . $data . "</a></td>" ;
      }
    }
  }else{
    echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
  }
  echo "</table>";
}
else
{
  echo "Error in running query :". mysql_error();
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/74285-help-with-hyperlink/#findComment-375343
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.