Links in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brad82
Forum Newbie
Posts: 2
Joined: Mon May 26, 2008 1:50 pm

Links in php

Post by brad82 »

Hi,
I have some script that grabs a load of urls and titles from a database. Here is the code I am using

Code: Select all

 
<link href="../CSS/tutlist.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function download(){
<?php
$page = "trigger.php?";
$link = "";
//redirect them to the download page :)
echo '<meta http-equiv="refresh" content="0;url=trigger.php?$link">';
?>
}
</script>
 
<?php
//***********************
include ("../cgi-bin/dbconnect.php");
//***********************
$sql = "select * from tutorials";
       $result = mysql_query ($sql);
 
       while ($row = mysql_fetch_array($result))
              {
              $field1= $row["title"];
              $field2= $row["description"];
              $field3= $row["url"];
 
echo "<div class='tableText'><a href='javascript&#058;download()' <?php $link = $field3; ?>$field1</div></a>";
echo "<div class='tableText'>$field2</div>";
 
 
              }
?>
 
What I want to do is when the title is clicked it changes $link to the $url from the database and executes the function download(). The part I do not know how to do is change the $link to the $url from the database when the title is clicked
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Links in php

Post by califdon »

brad82 wrote:Hi,
I have some script that grabs a load of urls and titles from a database. Here is the code I am using

Code: Select all

 
<link href="../CSS/tutlist.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function download(){
<?php
$page = "trigger.php?";
$link = "";
//redirect them to the download page :)
echo '<meta http-equiv="refresh" content="0;url=trigger.php?$link">';
?>
}
</script>
 
<?php
//***********************
include ("../cgi-bin/dbconnect.php");
//***********************
$sql = "select * from tutorials";
       $result = mysql_query ($sql);
 
       while ($row = mysql_fetch_array($result))
              {
              $field1= $row["title"];
              $field2= $row["description"];
              $field3= $row["url"];
 
echo "<div class='tableText'><a href='javascript&#058;download()' <?php $link = $field3; ?>$field1</div></a>";
echo "<div class='tableText'>$field2</div>";
 
 
              }
?>
 
What I want to do is when the title is clicked it changes $link to the $url from the database and executes the function download(). The part I do not know how to do is change the $link to the $url from the database when the title is clicked
I'm not sure I understand what you want to do. $link is a PHP variable, by the time the user sees the page and can click on anything, the PHP is finished, so it cannot possibly react to a click. What are you trying to achieve? Wouldn't a simple hyperlink do what you want?
Post Reply