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("GetSQLV alueString ")) {
function GetSQLValueString($theValu e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea l_escape_s tring") ? mysql_real_escape_string($ theValue) : mysql_escape_string($theVa lue);
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_Reco rdset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1' ];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$searchterm_Recordset1 = "4X4X4";
if (isset($_REQUEST['searchte rm'])) {
$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($searcht erm_Record set1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_R ecordset1, $sb0) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Records et1);
if (isset($_GET['totalRows_Re cordset1'] )) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset 1'];
} else {
$all_Recordset1 = mysql_query($query_Records et1);
$totalRows_Recordset1 = mysql_num_rows($all_Record set1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1 /$maxRows_ Recordset1 )-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_ST RING'])) {
$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_Record set1=%d%s& searchterm =%s",
$totalRows_Recordset1, $queryString_Recordset1, urlencode($searchterm_Reco rdset1));
?>
<!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></sp an></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_Records et1=%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_Records et1=%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_Records et1=%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_Records et1=%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_Produ ct_Code</t h>
<th scope="col">Description</t h>
<th scope="col"><div align="center">Supplier_Na me</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</di v></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_Co de']; ?></td>
<td><?php echo $row_Recordset1['Descripti on']; ?></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($Records et1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Records et1);
?>
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/
<?php
if (!function_exists("GetSQLV
function GetSQLValueString($theValu
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea
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_Reco
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$searchterm_Recordset1 = "4X4X4";
if (isset($_REQUEST['searchte
$searchterm_Recordset1 = $_REQUEST['searchterm'];
}
mysql_select_db($database_
$query_Recordset1 = sprintf("SELECT * FROM Boxes, Suppliers WHERE MATCH (Description) AGAINST ( %s) AND Boxes.SID = Suppliers.SID ORDER BY Suppliers.Supplier_Name ASC", GetSQLValueString($searcht
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_R
$row_Recordset1 = mysql_fetch_assoc($Records
if (isset($_GET['totalRows_Re
$totalRows_Recordset1 = $_GET['totalRows_Recordset
} else {
$all_Recordset1 = mysql_query($query_Records
$totalRows_Recordset1 = mysql_num_rows($all_Record
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_ST
$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_Record
$totalRows_Recordset1, $queryString_Recordset1, urlencode($searchterm_Reco
?>
<!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
</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
</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_Records
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Records
<?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_Records
<?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_Records
<?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_Produ
<th scope="col">Description</t
<th scope="col"><div align="center">Supplier_Na
<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 width="250" scope="col"><div align="center">Website</di
<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_
<td><?php echo $row_Recordset1['Descripti
<td><div align="left"><?php echo $row_Recordset1['Supplier_
<td width="100"><div align="center"><?php echo $row_Recordset1['Tollfree'
<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']
<td width="200"><?php echo $row_Recordset1['Address']
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Records
</table>
</body>
</html>
<?php
mysql_free_result($Records
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
typing in the same time... :-(
Not quite the same time :)
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?
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.
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.