I have coded a PHP Contact List that gets data from a MySQL Database, it all works perfecty but want I want to do is make the Email Field a mailto: Hyperlink so the user can click on the email link.
__________________________________________________ _________________
Current Page
<HTML>
<HEAD>
<TITLE>Contact List</TITLE>
</HEAD>
<BODY>
<?php
//First off, let's list our variables that will connect to the database
$dbname="altrowcolor";
$dbtable="altrowcolordata";
$hostserver="localhost"; //whatever your host's serve's IP or address is, here its my local server.
$username="test";
$password="test";
$db = @mysql_connect("$hostserver","$username","$passwor d")//the connection statement using
// the @ error supressor.
or die ("Problems connecting to database server"); //die statements kill the script at this point if
//an unsuccessful connection is made.
@mysql_select_db ("$dbname") or die ("Problem selecting database");
$query = "SELECT * FROM $dbtable ORDER BY ID ASC"; //the SQL query ordered by the ID column ascending.
$result = @mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows =@mysql_num_rows($result);
//Ok, we have our data from our database. Now we just need to open up our table
//and run a for loop for as many rows as we have and display the data. Then, we close the table.
?>
<!-- switched into HTML mode to start our table -->
<TABLE width="460" BORDER="0" cellpadding="3" cellspacing="1">
<TR bgcolor="lightblue"><TD width="191">Row Number</TD>
<TD width="122">Date</TD>
<TD width="125">Email</TD></TR>
<?php
//back into PHP mode using your familiar for loop
for ($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_assoc($result); //get a row from our result set
if ($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"yellow\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#CCCCCC\">\n";
}
echo "<TD>".$row['SomeText']."</TD><TD>".$row['SomeDate']."</TD><TD>".$row['Email']."</TD>\n";
echo "</TR>\n";
}
?>
<!-- now let's close the table and be done with it -->
</TABLE>
</BODY>
</HTML>
__________________________________________________ ____
SQL DumpFile
# phpMyAdmin SQL Dump
# version 2.5.6
#
http://www.phpmyadmin.net
#
# Host: localhost
# Generation Time: May 23, 2004 at 01:12 PM
# Server version: 4.0.18
# PHP Version: 4.3.4
#
# Database : `altrowcolor`
#
# --------------------------------------------------------
#
# Table structure for table `altrowcolordata`
#
CREATE TABLE `altrowcolordata` (
`ID` int(15) NOT NULL auto_increment,
`SomeText` varchar(15) NOT NULL default '',
`SomeDate` date NOT NULL default '0000-00-00',
`Email` varchar(150) NOT NULL default '',
PRIMARY KEY (`ID`)
) TYPE=MyISAM AUTO_INCREMENT=11 ;
#
# Dumping data for table `altrowcolordata`
#
INSERT INTO `altrowcolordata` VALUES (1, 'Row 1', '2003-04-01', 'matthew@test.com.au');
INSERT INTO `altrowcolordata` VALUES (2, 'Row 2', '2003-04-02', 'row2@test.com.au');
INSERT INTO `altrowcolordata` VALUES (3, 'Row 3', '2003-04-03', '');
INSERT INTO `altrowcolordata` VALUES (4, 'Row 4', '2003-04-04', '');
INSERT INTO `altrowcolordata` VALUES (5, 'Row 5', '2003-04-05', '');
INSERT INTO `altrowcolordata` VALUES (6, 'Row 6', '2003-04-06', '');
INSERT INTO `altrowcolordata` VALUES (7, 'Row 7', '2003-04-07', '');
INSERT INTO `altrowcolordata` VALUES (8, 'Row 8', '2003-04-08', '');
INSERT INTO `altrowcolordata` VALUES (9, 'Row 9', '2003-04-09', '');
INSERT INTO `altrowcolordata` VALUES (10, 'Row 10', '2003-04-10', '');
Can someone plese help me, you can either reply to me via email
mail@matthewscomputerguide.com or post in the forum thread.
Thanks
Matthew