Jump to content

how to increment a link


redarrow

Recommended Posts

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.
[code]

<?

$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>";

}

?>

[/code]

Link to comment
Share on other sites

something like this is one simplified way of doing it
[code]
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 />";
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.