When pulling info from db, how to link to email or URL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

When pulling info from db, how to link to email or URL

Post by cdickson »

Once I pull information from a database and into a table, how do I then link an email address or URL to the appropriate location?

For example, I have created a table that pulls members of a chamber of commerce into a PHP page. In the database the email addresses and URLs simply show as text, and I don't know how to set up active links.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Code: Select all

<?php

while($row = mysql_fetch_assoc($query)){
echo "<a href="mailto:$row['email']">$row['email']</a>";
}

?>
Same thing for urls. At least that is how I do it... ;)
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

Thanks, Steve. Unfortunately I did not mention :oops: - nor include code - the fact that I am using Dreamweaver MX, which generates different code because of the recordsets. If my PHP code currently reads:

Code: Select all

<?php
$maxRows_rsFlorists = 500;
$pageNum_rsFlorists = 0;
if (isset($_GET['pageNum_rsFlorists'])) {
  $pageNum_rsFlorists = $_GET['pageNum_rsFlorists'];
}
$startRow_rsFlorists = $pageNum_rsFlorists * $maxRows_rsFlorists;

mysql_select_db($database_hschamber, $hschamber);
$query_rsFlorists = "SELECT * FROM Members WHERE cat_id1 = '79' OR cat_id2 = '79' OR cat_id3 = '79' ORDER BY member_name";
$query_limit_rsFlorists = sprintf("%s LIMIT %d, %d", $query_rsFlorists, $startRow_rsFlorists, $maxRows_rsFlorists);
$rsFlorists = mysql_query($query_limit_rsFlorists, $hschamber) or die(mysql_error());
$row_rsFlorists = mysql_fetch_assoc($rsFlorists);

if (isset($_GET['totalRows_rsFlorists'])) {
  $totalRows_rsFlorists = $_GET['totalRows_rsFlorists'];
} else {
  $all_rsFlorists = mysql_query($query_rsFlorists);
  $totalRows_rsFlorists = mysql_num_rows($all_rsFlorists);
}
$totalPages_rsFlorists = ceil($totalRows_rsFlorists/$maxRows_rsFlorists)-1;
?>
where do I insert the command? And is it the same as you suggested based on the different code I have?

Thanks for helping out! :D
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Have you played with the code? Try inserting it - if it breaks, click undo. If not: congrats. :)
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

patrikG wrote:Have you played with the code? Try inserting it - if it breaks, click undo. If not: congrats. :)
LMAO! So true!!!
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

LMAO too for me being such a dorky newbie! :oops:
Thanks for the help - I appreciate it.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

i used dreamweaver for a few weeks for my first ever PHP app

i cannot emphasise more that you should move away from DW's in built features and code by hand yourself because:
1 - lots of unnecessary code = Bloated Apps
2 - you will never learn this way
3 - Old syntax may become defunct soon, and break your site
4 - more complex to add functionality due to weird coding style

just a few reasons........
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

Thanks for the advice. I have reached that very same conclusion.

Unfortunately this is my first PHP project and I have a deadline to meet, so I will probably have to get it up and running, and then recode each page as I have time. A lot of it is repetitive, so I will be able to copy and paste much of it.

In the meantime I have purchased several books to help me learn PHP more intimately.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

A good free editor, if you're looking for one, is PHPEdit - I think the website is http://www.phpedit.net/
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

Thanks for the tip, patrikG. I didn't know these PHP editors existed - and you obviously know what it is like to hand code in Notepad. 8O

I am working on re-coding my pages - your help has been invaluable, and I am truly apprecative.
Post Reply