JTapp Posted April 17, 2008 Share Posted April 17, 2008 This is what I have: echo "<a href=\"$FIELDNAMEHERE\">Click Here To Go To The Website</a>"; But the link is taking me to my own site...? Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/ Share on other sites More sharing options...
Daniel0 Posted April 17, 2008 Share Posted April 17, 2008 What's your question? Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519547 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 Well, the variable's value is probably empty. View the srouce on the rendered page and you might find it looking like this: <a href="">Click Here To Go To The Website</a> Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519548 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 Maybe I don't need the $ sign... My original problem is this - FIELDNAME has a website link stored in the database. The link is being returned, but it is not an 'active' hyperlink. I started out with this : echo $row["FIELDNAME"]; Then by playing around, I ended up with my original post.. both are wrong. Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519555 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 Without more code we have no idea what's wrong. Have your tried just echo'ing the variable alone? use print_r($GLOBALS) and show us your non-sensitive variables that are defined. Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519561 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 I wasn't trying to do the variable thing.. just a direct field name... does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519591 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 No. You mean a form field? Has the form been submitted? If not, you must use javascript. Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519616 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 Hmmm.. Java.. it may be true.. I'm not sure. Let me approach my problem/question from a different angle. The following code returns my data just fine into a results.php. One of my fields is an Email address - which is displaying the contact email address just fine. However, I would like to have the email link activated so the user can click on the email address and Outlook (or whatever) will open. Below is the code just below the query.. the field name is "Email" $result = mysql_query($query) or die(mysql_error()); echo "<table width=\"65%\" border=\"2\" bgcolor=\"#EBECE4\">"; echo "<tr><td><B>District Officer Title<B></td><td><B>First Name<B></td><td><B>Last Name<B></td><td><B>Office Phone<B></td><td><B>Email<B></td></tr>"; while ( $row = mysql_fetch_array($result)) { echo "<tr><td>". $row['strOfficerTitle'] . "</td><td>" . $row['strFirstName'] . "</td><td>" . $row['strLastName'] . "</td><td>" . $row['OfficePhone'] . "</td><td>" . $row['Email'] . "</td></tr>"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519650 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 ...<a href=\"mailto:{$row['Email']}\">{$row['Email']}</a>... Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519653 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 I don't think I plugged it in correctly because I get a blank page with this: echo "<tr><td>". $row['strOfficerTitle'] . "</td><td>" . $row['strFirstName'] . "</td><td>" . $row['strLastName'] . "</td><td>" . $row['OfficePhone'] . "</td><td>" . <a href=\"mailto:{$row['Email']}\">{$row['Email']}[/url] . "</td></tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519668 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 Stupid broken BBCODE parser ugh. I hate SMF echo "<tr><td>". $row['strOfficerTitle'] . "</td><td>" . $row['strFirstName'] . "</td><td>" . $row['strLastName'] . "</td><td>" . $row['OfficePhone'] . "</td><td><a href=\"mailto:{$row['Email']}\">{$row['Email']}</a></td></tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519671 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 Yes, that worked.. thanks! So, if my 'Email' field was actually 'Website'.. would the following be accurate? echo "<tr><td>". $row['strOfficerTitle'] . "</td><td>" . $row['strFirstName'] . "</td><td>" . $row['strLastName'] . "</td><td>" . $row['OfficePhone'] . "</td><td><a href=\"{$row['Website']}\">{$row['Website']}</a></td></tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519677 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 Should work. Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519686 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 Well, I tried and tried to work with what you provided to me without bugging you again.. but I got nowhere. I get returned: [/url] (which is a link to my own site.) Here is my code - I didn't want the URL link to be in the table, I wanted it to be alone and above it... $result = mysql_query($query) or die(mysql_error()); echo "<p><H2>Website:</H2> <a href=\"{$row['strDistrictWebSite']}\">{$row['strDistrictWebSite']}[/url]</p>"; echo "<table width=\"65%\" border=\"1\" bgcolor=\"#EBECE4\">"; echo "<tr><td><B>District Officers<B></td><td><B>First Name<B></td><td><B>Last Name<B></td><td><B>Office Phone<B></td><td><B>Email<B></td></tr>"; while ( $row = mysql_fetch_array($result)) { echo "<tr><td>". $row['strOfficerTitle'] . "</td><td>" . $row['strFirstName'] . "</td><td>" . $row['strLastName'] . "</td><td>" . $row['OfficePhone'] . "</td><td><a href=\"mailto:{$row['Email']}\">{$row['Email']}</a></td></tr>";} echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519704 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 Check where you define the $row array. Is it defined when you echo $row['strDistrictWebSite'] ? Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519711 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 I'm not sure what you are asking...(newbie here) Here is all of my php: <?php $username = "username"; $password = "password"; $hostname = "localhost"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("dbb",$dbhandle) or die("Could not select dbb"); $id = $_POST['search']; echo "<p><H2>District Number:</b> $id</H2></p>"; $query = "SELECT a.strLodgeName, a.intLodgeNumber, a.intDistrictID, a.strLodgeMailingCity, a.strLodgeMailingPostCode, b.strDistrictName, b.strDistrictWebSite, c.strOfficerTitle, c.strFirstName, c.strLastName, c.OfficePhone, c.Email FROM tblDistricts AS b LEFT JOIN tblLodges AS a ON b.intDistrictID = a.intDistrictID LEFT JOIN DistrictOfficers AS c ON a.intDistrictID = c.intDistrictID WHERE b.intDistrictID='$id' GROUP BY c.strOfficerTitle LIMIT 5"; $result = mysql_query($query) or die(mysql_error()); echo "<p><H2>District Website:</H2> <a href=\"{$row['strDistrictWebSite']}\">{$row['strDistrictWebSite']}[/url]</p>"; echo "<table width=\"65%\" border=\"1\" bgcolor=\"#dddddd\">"; echo "<tr><td><B>District Officers<B></td><td><B>First Name<B></td><td><B>Last Name<B></td><td><B>Office Phone<B></td><td><B>Email<B></td></tr>"; while ( $row = mysql_fetch_array($result)) { echo "<tr><td>". $row['strOfficerTitle'] . "</td><td>" . $row['strFirstName'] . "</td><td>" . $row['strLastName'] . "</td><td>" . $row['OfficePhone'] . "</td><td><a href=\"mailto:{$row['Email']}\">{$row['Email']}</a></td></tr>";} echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519714 Share on other sites More sharing options...
craygo Posted April 17, 2008 Share Posted April 17, 2008 you will have to return the query results first. so you will need to do it before you echo out the link. $result = mysql_query($query) or die(mysql_error()); $link = mysql_fetch_assoc($result); echo "<p><H2>Website:</H2> <a href=\"{$link['strDistrictWebSite']}\">{$link['strDistrictWebSite']}</a></p>"; echo "<table width=\"65%\" border=\"1\" bgcolor=\"#EBECE4\">"; echo "<tr><td><B>District Officers<B></td><td><B>First Name<B></td><td><B>Last Name<B></td><td><B>Office Phone<B></td><td><B>Email<B></td></tr>"; while ( $row = mysql_fetch_array($result)) { echo "<tr><td>". $row['strOfficerTitle'] . "</td><td>" . $row['strFirstName'] . "</td><td>" . $row['strLastName'] . "</td><td>" . $row['OfficePhone'] . "</td><td><a href=\"mailto:{$row['Email']}\">{$row['Email']}</a></td></tr>";} echo "</table>"; ?> Not tested but try it out. If not you will need to use an if statement to do it inside the loop. BTW anything in this forum that has [/url] should be replaced with </a> . The forum changes the code on it's own. Ray Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519718 Share on other sites More sharing options...
JTapp Posted April 17, 2008 Author Share Posted April 17, 2008 Thanks craygo - works beautifully! Quote Link to comment https://forums.phpfreaks.com/topic/101574-solved-simple-echo-to-activate-hyperlink-field-but-ive-got-it-wrong/#findComment-519734 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.