Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Code Help


PHP Code Help

Reply
  #1 (permalink)  
Old 05-22-04, 10:16 PM
matt001 matt001 is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code Help

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
Reply With Quote
  #2 (permalink)  
Old 05-22-04, 10:44 PM
Lost Lost is offline
Wannabe Coder
 
Join Date: Mar 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
You question is a little hard to understand but I think you just want to make the outputted email a mailto hyperlink. If so, here is a code snippet. The red area is the edited part.

<?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><a href=\"mailto:".$row['Email']."\">".$row['Email']."</a></TD>\n";
echo "</TR>\n";
}
?>
Reply With Quote
  #3 (permalink)  
Old 05-22-04, 11:26 PM
matt001 matt001 is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
I have now got the email hyperlink working all I need now is to change the font and font size of the data that comes out of the Database for example I may want to set the font size to 10 and the font to Arial.



<?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 -->
<style type="text/css">
<!--
.style7 {color: #FFFFFF; font-weight: bold; font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
-->
</style>

<table width="631" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#000000"> <TD width="150"><span class="style7">Row Number</span></TD><TD width="135"><span class="style7">Date</span></TD>
<TD width="99"><span class="style7">Email</span></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=\"#FFFFFF\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#F5F5F5\">\n";
}
echo "<TD>".$row['SomeText']."</TD><TD>".$row['SomeDate']."</TD><TD><a href=\"mailto:".$row['Email']."\">".$row['Email']."</a></TD>\n";
echo "</TR>\n";
}
?>
<!-- now let's close the table and be done with it -->
</TABLE>
</BODY>
</HTML>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 04:03 AM
Use this code outside of PHP tags? D_tunisia PHP 6 04-12-04 12:06 PM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 12:10 PM
Generating PHP code for MySQL ptesone General Advertisements 1 02-03-04 08:26 AM
protecting code in PHP ckb PHP 12 01-02-04 08:53 AM


All times are GMT -5. The time now is 10:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.