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
}
?>