Link to home
Start Free TrialLog in
Avatar of DomerBill
DomerBill

asked on

Hyperlink E-mail and Web Address

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);
?>

ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
typing in the same time... :-(
Not quite the same time :)
Avatar of DomerBill
DomerBill

ASKER

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?
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.