sandbudd Posted March 31, 2009 Share Posted March 31, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/ Share on other sites More sharing options...
sandbudd Posted March 31, 2009 Author Share Posted March 31, 2009 did this <a href="<?php echo $row_Recordset1['website']; ?>"><?php echo $row_Recordset1['website']; ?></a> now it is clickable but points to the original site and the clickable site... example url. http://www.mysite.com/www.othersite.com Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798138 Share on other sites More sharing options...
sandbudd Posted March 31, 2009 Author Share Posted March 31, 2009 don't know if I need back slashes or what? Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798149 Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798153 Share on other sites More sharing options...
sandbudd Posted March 31, 2009 Author Share Posted March 31, 2009 thank you soooo much something that simple you are the champ works great! Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798158 Share on other sites More sharing options...
sandbudd Posted March 31, 2009 Author Share Posted March 31, 2009 thought I was done how do I make the link open another browser... _blank? Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798163 Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 <span class="style3"><a href="<?php echo $website; ?>" target="_blank"><?php echo $website; ?></a></span><br /></span><br /><br /> Yep...try it out. You may save yourself some time by trying it first Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798164 Share on other sites More sharing options...
sandbudd Posted March 31, 2009 Author Share Posted March 31, 2009 lost the link all together? Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798166 Share on other sites More sharing options...
sandbudd Posted March 31, 2009 Author Share Posted March 31, 2009 this worked <span class="style3"><a href="http://<?php echo $row_Recordset1['website']; ?>" target="_blank"><?php echo $row_Recordset1['website']; ?></a></span><br /></span><br /><br /> Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798170 Share on other sites More sharing options...
sandbudd Posted March 31, 2009 Author Share Posted March 31, 2009 Thank you again premiso Quote Link to comment https://forums.phpfreaks.com/topic/151982-solved-sql-clickable-link-troubles/#findComment-798171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.