Solved

Hyperlink E-mail and Web Address

Posted on 2009-05-13
6
397 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

821 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