Jump to content

[SOLVED] sql clickable link troubles


sandbudd

Recommended Posts

Guys I have tried several combos trying to make a sql query clickable and cant make it work.  What I have is a table that is calling a website url put in but can not figure out to make the link clickable?  I know that this is a basic question but I cant seem to figure it out.  here is the complete code.  on line 78  <span class="style3"><?php echo $row_Recordset1['website']; ?></span><br /></span><br /><br /> this is what I need clickable.  This is done in Dreamweaver which I know you guys probably hate.

 

<?php require_once('../Connections/fwragain.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;
}
}

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

mysql_select_db($database_fwragain, $fwragain);
$query_Recordset1 = "SELECT * FROM employees";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $fwragain) 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;
?><!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">
<!--
.style3 {font-family: Arial, Helvetica, sans-serif; font-size: 11px; }
.style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
-->
</style>
</head>

<body>
<table width="299" border="0" cellpadding="0" cellspacing="0">
  
  <?php do { ?>
    <tr>
      <td width="244"><span class="style4"><?php echo $row_Recordset1['company']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['address']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['city']; ?></span><span class="style3">,</span><span class="style3"><?php echo $row_Recordset1['state']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['phone']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['website']; ?></span><br /></span><br /><br />
      <td width="55" colspan="4" align="center" valign="middle"><?php echo "<img src=http://www.fortwaynerestaurant.net/images/".$row_Recordset1['photo'] ."> "; ?><br/></td>
    </tr>
    
    
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Link to comment
https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/
Share on other sites

The issue you are having is websites with just www that are hyperlinked will have the current site's address auto added. To prevent this, add http:// and it will be fine. But make sure your links in the DB do not have the http:// if they do this will cause an issue.

 

        <span class="style3"><a href="http://<?php echo $row_Recordset1['website']; ?>"><?php echo $row_Recordset1['website']; ?></a></span><br /></span><br /><br />

 

Alternatively, if you have mixed in the DB, this will solve that issue.

 

  <?php do { 
         $website = (stristr($row_Recordset1['website'], "http://") !== false)?$row_Recordset1['website']:"http://" . $row_Recordset1['website'];
?>
    <tr>
      <td width="244"><span class="style4"><?php echo $row_Recordset1['company']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['address']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['city']; ?></span><span class="style3">,</span><span class="style3"><?php echo $row_Recordset1['state']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['phone']; ?></span><br />
        <span class="style3"><a href="<?php echo $website; ?>"><?php echo $website; ?></a></span><br /></span><br /><br />
      <td width="55" colspan="4" align="center" valign="middle"><?php echo "<img src=http://www.fortwaynerestaurant.net/images/".$row_Recordset1['photo'] ."> "; ?><br/></td>
    </tr>
     
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

 

The ? and : in the $website statement is called the ternary operator and is basically a shortened If/Else statement.

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.