calling php function on click of a hyperlink

This is a discussion on "calling php function on click of a hyperlink" within the PHP Forum section. This forum, and the thread "calling php function on click of a hyperlink are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 15th, 2007, 15:27
Up'n'Coming Member
Join Date: Jul 2006
Location: manila
Age: 28
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
calling php function on click of a hyperlink

How to call a php function on click of a hyperlink??

the url and title is in the database

e.g

title : yyy
url : www.yyy.com

<a href="url" ><? echo $row['title']; ?></a>

correct me if im wrong..

thanks
Reply With Quote

  #2 (permalink)  
Old Jul 15th, 2007, 15:56
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: calling php function on click of a hyperlink

Quote:
How to call a php function on click of a hyperlink??
Don't really know what you mean. Do you mean that when you click on the link PHP is executed, or do you mean you want PHP to generate the link?

Quote:
<a href="url" ><? echo $row['title']; ?></a>
If you have connected to the database beforehand and $row is defined, that should work fine. If you are wanting "url" to be displayed from the database, you need to do the same as you have done for the title.
I.e.
PHP: Select all

<a href="<? echo $row['url']; ?>"><? echo $row['title']; ?></a>
Normally that would be in a while loop.
E.g.
PHP: Select all

while($row mysql_fetch_array($result))
  {
  echo(
"
     <a href=\"$row['url']\">$row['title']</a>
  "
);
  } 
So some working code might be:
PHP: Select all

<?php
$db_username
="username";
// database username
$db_password="password";
// database password
$database="mydatabase_db";
// name of database

/* connect to db */
mysql_connect("localhost",$db_username,$db_password);
// connect to database using login info specified above

@mysql_select_db($database) or die( "Unable to select database");

$query "SELECT * FROM links";
// select all from links table SQL query
$result mysql_query($query);
// run SQL query 

while($row mysql_fetch_array($result))
// fetches results for and puts them in an array, then does the same for the next row until rows run out.
  
{
  echo(
"
     <a href=\"$row['url']\">$row['title']</a>
     "
);
     
// echoes your link
  
}

?>

Last edited by balaclave; Jul 15th, 2007 at 15:59.
Reply With Quote
  #3 (permalink)  
Old Jul 15th, 2007, 16:27
Up'n'Coming Member
Join Date: Jul 2006
Location: manila
Age: 28
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: calling php function on click of a hyperlink

hey body, great it works thank you very much ...
Reply With Quote
Reply

Tags
hyperlink

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
calling functions in a function fatsurfer PHP Forum 1 Jun 12th, 2008 21:53
problem calling function via onClick Eagle JavaScript Forum 5 Jan 15th, 2007 21:41
plz help me verify this... calling function melvinoyh JavaScript Forum 0 May 29th, 2006 01:35
Difficulty calling a javascript function? grittyminder JavaScript Forum 4 Jul 21st, 2005 17:48
calling a javascript function in from VBscript jakyra Classic ASP 2 Sep 22nd, 2003 23:13


All times are GMT. The time now is 07:18.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43