Solved

Hyperlink E-mail and Web Address

Posted on 2009-05-13
6
383 Views
Last Modified: 2013-12-12
I have a database for users to search suppliers. In the search results page, I have one column for E-mail and another for Website, in addition to other common supplier profile info.

How to set up the query so that when it returns records, the E-mail and Website will be displayed with hyperlinks. This way users can just click in the results page to send e-mails or visit the websites, instead of doing copy/paste.

I am using Dreamweaver CS3, PHP and MySql. Below are the code for my search result page. Thanks in advance for ideas or suggestions.

<?php require_once('Connections/sb0.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 25;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$searchterm_Recordset1 = "4X4X4";
if (isset($_REQUEST['searchterm'])) {
  $searchterm_Recordset1 = $_REQUEST['searchterm'];
}
mysql_select_db($database_sb0, $sb0);
$query_Recordset1 = sprintf("SELECT * FROM Boxes, Suppliers WHERE MATCH (Description) AGAINST ( %s) AND Boxes.SID = Suppliers.SID ORDER BY Suppliers.Supplier_Name ASC", GetSQLValueString($searchterm_Recordset1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $sb0) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false && 
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s&searchterm=%s",
  $totalRows_Recordset1, $queryString_Recordset1, urlencode($searchterm_Recordset1));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {color: #0033FF}
.style14 {font-family: "book Antiqua"; font-size: 24pt;}
.style15 {font-family: "segoe Print"; font-size: small;}
.style2 {      color: #00FF00;
      font-family: "script MT Bold";
      font-size: larger;
}
.style5 {font-family: "book Antiqua"}
-->
</style>
</head>

<body>

<form action="http://www.sourcesbook.com/Results.php" method="post" name="form1" target="_blank" id="form2">
  <div align="left">
    <p><span class="style1"><span class="style14">ENEN<span class="style2"><sup>n</sup></span> Coporation</span> <span class="style15">your sourcing partner<span class="style5">...</span></span></span></p>
  </div>
  <label></label>
  <label></label>
  <div align="justify"> </div>
  <p align="right"><span class="style9"><a href="Home.html" title="Home" target="_blank">Home</a> | <a href="Company.html" title="Company" target="_blank">Company</a> | <a href="Categories.html" title="Category" target="_blank">Cateogries</a> | <a href="Contact.html" target="_blank">Contact</a></span></p>
</form>

<p>Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?></p>
<table border="0">
  <tr>
    <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a>
          <?php } // Show if not first page ?>
    </td>
  <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a>
          <?php } // Show if not first page ?>
    </td>
  <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a>
          <?php } // Show if not last page ?>
    </td>
  <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a>
          <?php } // Show if not last page ?>
    </td>
  </tr>
</table>
<table width="2000" border="1" align="center">
  <tr>
    <th width="100" scope="col">PID</th>
    <th width="10" scope="col">Supplier_Product_Code</th>
    <th scope="col">Description</th>
    <th scope="col"><div align="center">Supplier_Name</div></th>
    <th width="100" scope="col">Tollfree</th>
    <th width="100" scope="col">Phone</th>
    <th width="100" scope="col">Fax</th>
    <th width="250" scope="col"><div align="center">Email</div></th>
    <th width="250" scope="col"><div align="center">Website</div></th>
    <th width="200" scope="col">Address</th>
  </tr>
  <?php do { ?>
    <tr>
      <td width="100"><?php echo $row_Recordset1['PID']; ?></td>
      <td width="10"><?php echo $row_Recordset1['Supplier_Product_Code']; ?></td>
      <td><?php echo $row_Recordset1['Description']; ?></td>
      <td><div align="left"><?php echo $row_Recordset1['Supplier_Name']; ?></div></td>
      <td width="100"><div align="center"><?php echo $row_Recordset1['Tollfree']; ?></div></td>
      <td width="100"><div align="center"><?php echo $row_Recordset1['Phone']; ?></div></td>
      <td width="100"><div align="center"><?php echo $row_Recordset1['Fax']; ?></div></td>
      <td width="250"><div align="left"><?php echo $row_Recordset1['Email']; ?></div></td>
      <td width="250"><div align="left"><?php echo $row_Recordset1['Website']; ?></div></td>
      <td width="200"><?php echo $row_Recordset1['Address']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>


</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

0
Comment
Question by:DomerBill
  • 3
  • 2
6 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 250 total points
ID: 24378798
>> How to set up the query so that when it returns records, the E-mail and Website will be displayed with hyperlinks

Change:

<td width="250"><div align="left"><?php echo $row_Recordset1['Email']; ?></div></td>
<td width="250"><div align="left"><?php echo $row_Recordset1['Website']; ?></div></td>

to

<td width="250"><div align="left"><a href="mailto:<?php echo $row_Recordset1['Email']; ?>">Send Email</a></div></td>
<td width="250"><div align="left"><a href="<?php echo $row_Recordset1['Website']; ?>">Visit Website</a></div></td>

0
 
LVL 10

Assisted Solution

by:Kechka
Kechka earned 250 total points
ID: 24378862
You just need to put the code for linking in your code. Something like this

<td width="250"><div align="left">
<a href="mailto:<?php echo $row_Recordset1['Email']; ?>"><?php echo $row_Recordset1['Email']; ?></a></div></td>
<td width="250"><div align="left">
<a href="<?php echo $row_Recordset1['Website']; ?>"><?php echo $row_Recordset1['Website']; ?></a>
</div></td>
0
 
LVL 10

Expert Comment

by:Kechka
ID: 24378869
typing in the same time... :-(
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 24378870
Not quite the same time :)
0
 

Author Comment

by:DomerBill
ID: 24379691
Both solutions work wonderful, though Kechka's allows the acutal e-mail and web addresses to display which I prefer a little bit more. Are you ok with me accepting multiple solutions?

Another question is how to let the uers' browser open a new page when they click the web address, instead of overwriting the search results page?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 24379737
You can do as you wish, since we were simul-posting anyway.  

The solutions are functionally identical...you need to echo the email/web site in the HTML <a> tag and you can do whatever you want with the label.  My personal preference is to NOT display emails or URLs in results to avoid having issues with super long strings i.e.:

http://www.someonecouldntfindagoodshortdomainnamesotheyregisteredthisone.com/and/they/have/bad/site/structure/

>> Another question is...

In the future, one question per thread please.  Consider this a freebie:

<a href="whatever.html" target="_blank">Link text here</a>

target="_blank" opens the link in a new window.  Be careful about using this.  All modern browsers support tabs now so the user can decide to open the links as a new tab.  You really shouldn't force that choice on them.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now