Page 1 of 1

Links in php

Posted: Sun Jun 01, 2008 7:00 am
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

Re: Links in php

Posted: Sun Jun 01, 2008 4:05 pm
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?