R
E
S
O
U
R
C
E
S
       Home      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: menus, buttons, etc.
_______________________

Send us your questions.
_______________________

site search by freefind
_______________________

HOME
SEO, Google, Privacy
   and Anonymity
Browser Insanity
JavaScript
Popups and Tooltips
Free Website Search
HTML Form Creator
Animation
Buttons and Menus
Counters
Captchas
Image Uploading
CSS and HTML
PHP
AJAX
XPATH
Website Poll
IM and Texting
Databases—MySQL
   or Not MySQL
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs




Free Personal Status Boards (PSB™)

Free Standard Free PSB

Free PSB Pro Version

Free Social PSB

Free Social PSB Plus (with Email)

Free Business PSB

Free Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

PHP Variables in URL and Link Text

For our first of three PHP examples, we'll use retreiving data from a MySQL table (which PHP is very good at doing, which is why it's used so often to do this). Let's say we fetch all of a MySQL table's rows and display them. (If you're concerned with security, check here for security tips, where you'll see why, theoretically, every single echo or print statement should use the htmlspecialchars() function for it's output. But this page you're on is about PHP variables in URLs and link text and mailto links, not security.) In this first example, we establish a MySQL connection, then select all (which is what * means) from the table and print it out into a nice neat HTML table. One row is called 'URL' and we didn't need it in our display, but we did need it to create a link. Our goal is to make the 'Firstname' row all be links to the person's website. In this theoretical example, this will have been the reason the 'URL' field was entered into the database in the first place. So what's the syntax that gets a click on any Firstname data resulting in surfing off to a website? We stick the 'URL' row into a PHP variable $e, then stick this variable into another variable, $m, created with concatenation with link tag syntax. The only thing missing is the anchor tag that ends the link: </a> That gets put at the end of the PHP echo statement that comes next. Note that in echo $m.$row['Firstname']."</a>"; the $m is the link tag which is concatenated with the $row['Firstname'] variable and the end anchor to form an active HTML link. We could throw a target='_blank' attribute in the link tag to have it open on a new page, if desired. Note also that in $m="<a href='".$e."'>"; it's critical that the double quotes are next to the dots, not the single quotes. The positioning of quotes in echo $m.$row['Firstname']."</a>"; are likewise vital.

<?php
// Make a MySQL Connection
mysql_connect("localhost", "your_user_name", "your_password") or die(mysql_error());
mysql_select_db("name_of_db") or die(mysql_error());

// Retrieve all the data from the table as a MySQL Resource
$result = mysql_query("SELECT * FROM $table") or die(mysql_error());

echo "<table border='1' width='578'>";
echo "<tr><th width='141'>Name</th><th width='25'>Status</th><th width='412'>Comment</th></tr>";
// below—keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)) {
// then it prints out the contents of each row into a table
echo "<tr><td>";
$e=$row['URL'];
$m="<a href='".$e."'>";
echo $m.$row['Firstname']."</a>";
echo "</td><td>";
echo $row['Status'];
echo "</td><td>";
echo $row['Comment'];
echo "</td></tr>";
}
echo "</table>";
?>

For our second of three PHP examples, we'll use retreiving data from a MySQL table again. Let's say we fetch all of a MySQL table's rows and display them. In this situation, we have an 'Email' row so we are looking to send whoever clicks on the 'Firstname' person to that person's default email program so they can email them a message. This is a real, not theoretical example—we really are using this code. Note we added a subject to the email: PSB Mail. Anyway, this once more is a situation where the syntax is critical. Here we stick the 'Email' row in the PHP variable $e, and concatenate this into a mailto link. Placement of single and double quotes is vital. Then, like with the URL example, we concatenate together the parts of this mailto link so it becomes live and viable for emailing whoever 'Firstname' is.

<?php
// Make a MySQL Connection
mysql_connect("localhost", "your_user_name", "your_password") or die(mysql_error());
mysql_select_db("name_of_db") or die(mysql_error());

// Retrieve all the data from the table as a MySQL Resource
$result = mysql_query("SELECT * FROM $table") or die(mysql_error());

echo "<table border='1' width='578'>";
echo "<tr><th width='141'>Name</th><th width='25'>Status</th><th width='412'>Comment</th></tr>";
// below—keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)) {
// then it prints out the contents of each row into a table
echo "<tr><td>";
$e=$row['Email'];
$m="<a href='mailto:".$e."?subject=PSB Mail'>";
echo $m.$row['Firstname']."</a>";
echo "</td><td>";
echo $row['Status'];
echo "</td><td>";
echo $row['Comment'];
echo "</td></tr>";
}
echo "</table>";
?>

For our third of three PHP examples, we'll use retreiving data from a MySQL table again. Let's say we fetch all of a MySQL table's rows and display them. But this time we don't want the 'Firstname' row to be a link, but just a column that gets displayed. In this situation, we have a displayed 'Email' row so we are looking to send whoever clicks on this 'Email' row to that person's default email program so they can email them a message. This is a theoretical example—we didn't need this exact code, but did need the second example, above. Note we added a subject to the email: PSB Mail. Anyway, this once more is a situation where the syntax is critical. Here we stick the 'Email' row in the PHP variable $e, and concatenate this into a mailto link. Placement of single and double quotes is vital. Then, like with the other examples, we concatenate together the parts of this mailto link so it becomes live and viable for emailing whoever got their email address in this 'Email' field.

<?php
// Make a MySQL Connection
mysql_connect("localhost", "your_user_name", "your_password") or die(mysql_error());
mysql_select_db("name_of_db") or die(mysql_error());

// Retrieve all the data from the table as a MySQL Resource
$result = mysql_query("SELECT * FROM $table") or die(mysql_error());

echo "<table border='1' width='578'>";
echo "<tr><th width='141'>Name</th><th width='25'>Status</th><th width='412'>Comment</th></tr>";
// below—keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)) {
// then it prints out the contents of each row into a table
echo "<tr><td>";
echo $row['Firstname'];
echo "</td><td>";
$e=$row['Email'];
$m="<a href='mailto:".$e."?subject=PSB Mail'>";
echo $m.$row['Email']."</a>";
echo "</td><td>";
echo $row['Status'];
echo "</td><td>";
echo $row['Comment'];
echo "</td></tr>";
}
echo "</table>";
?>