Jump to content


Photo

how to increment a link


  • Please log in to reply
1 reply to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 May 2006 - 07:48 AM

Advance thank you.

I am learnig php and i want to learn how to get a link to increment and update the database each time the link is pressed.


Got no idear how to do this just an example of what i want to do.

<?

$db=mysql_conect("loclhost");
mysql_select_db("test",$db);
$query="select * from link where links='$links'";
$result_mysql_query($query);

if(mysql_num_rows($result)==0) {

$query="insert into link (links)values('$links')";
$result_mysql_query($query);

<a href="http//www.whatever.com">goto page</a>

}

if(mysql_num_rows($result)==1) {

$query="update link set links='$links++' ";
$result_mysql_query($query);

}

$query="select * from link where links='$links'";
$result_mysql_query($query);
while(record=mysql_fetch_assoc($result){
while(list($tablename,$data)=each($record){

echo"<br>number of  times $tablename has been pressed $data<br>";

}

echo"<br>";

}

?>



Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 06 May 2006 - 08:38 AM

something like this is one simplified way of doing it
if(!empty($_GET['url']))
{
  $url = htmlspecialchars($_GET['url']);
  mysql_query("update links set hits = hits + 1 where url='$url'");
  header("Location: $url");
  exit();
}

$get_links = mysql_query("select url from links");
while($row = mysql_fetch_array($get_links))
{
  $url = $row['url'];
  print "<a href="this_page.php?url=$url" target="_blank">$url</a>";
  print "<br />";
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users