Jump to content

Archived

This topic is now archived and is closed to further replies.

fullyloaded

download count

Recommended Posts

you would make a link to a page and the link would have an id pass to it.  You would then update a field in your database based on the id and then output the filename based on the id.

Share this post


Link to post
Share on other sites
The id is comming from a session in my example good luck.


url.php 
[code]
<?php session_start();

echo "<a href='update_counter.php?id=$id&cmd=update'>goto the page you want</a>";

?>
[/code]


update_counter.php

[code]
<?php session_start();

if($_GET['cmd']=='update'){

$query="UPDATE counter set stats=stats+1 WHERE id='$id'";
result=mysql_query($query);

header("location: To the page where the user wanted to go from the link.php");

}else{

header("location: back to home page if they go to this update page directly");

}
?>

[/code]

if you use the above defult then your be adding a count of 1 to the stats table but if you added 100 to the stats table and used A - YOUR BE DEDUCTING FROM 100 OK.

Share this post


Link to post
Share on other sites
okay first of all:
[quote]
if you use the above defult then your be adding a count of 1 to the stats table but if you added 100 to the stats table and used A - YOUR BE DEDUCTING FROM 100 OK.
[/quote]
that makes absolutely no sense at all. I [i]think[/i] you are giving an example of an alternate way to keep track, like counting up vs. counting down?

2nd, Can you please explain to me how your code has anything to do with sessions? I mean, I can sorta kinda see that you are providing an example of listing the id's for the links, but I fail to see how that's even remotely necessary? I would assume that one would do a query of some kind to get the id numbers, creating the links in a loop, or some other such similar fashion.  I don't really see the point in carrying over the list of IDs in a session. 

I hope that you are not trying to say that $_GET variables are session variables..

Share this post


Link to post
Share on other sites
Crayon Violent sorry if my code made no scence but hopefully this does all the best redarrow.


This code will dispaly 3 links and if the link is pressed will goto a update page and then the user is tacken to the page they wanted.

if the user goes directly to the update page the page takes them to your home page (index.php)

All you got to do is copy and past the code and add the database information.


warning. I have used the ob_start and ob_flush_end on the code to stop header
problams but if you get header erros then you should relly sort them out all
the best redarrow.


The last thing i want to exsplain your see in the query that i got the stats=stats+1 that adds a 1 each time the link is pressed and for the correct page example index.php.

But if you insert in stats a number of 100 you can then count downwords examlpe stats=stats-1 this would take one from the 100 and ecah time deduct 1 from the database.

hope you understand cheers.

databse information.

[code]
create database page_stats;

use page_stats;

create table counter(
id int not null primary key auto_increment,
page_name varchar(20) not null ,
stats int not null
);

insert into page_stats (page_name,stats) values (index.php,'1');
insert into page_stats (page_name,stats) values (contact.php,'1');
insert into page_stats (page_name,stats) values (links.php,'1');
[/code]

test.php

[code]
<?php

// set an array for the links to display and the pages needed.

$page=array(index_page =>'index.php',contact_page =>'contact.php',links_page
=>'links.php');


// for loop the amount of pages there are.
for($i=1; $i<2; $i++){


// get the information from the array.

foreach($page as $v => $x){

// echo the three links.

echo "<a href='test_result.php?cmd=update&page_name=$x'>$v</a><br>";

}
}
?>

[/code]


test_result.php
[code]

<?php

// so the header does not error out a message.
ob_start();

// post the varables.
$page_name=addslashes($_POST['page_name']);
$stats=addslashes($_POST['stats']);

// database connection.

$db=mysql_connect('localhost','xxxxxx','xxxxxxxx');
mysql_select_db('page_stats',$db);


// $_GET the url condirition.

if($_GET['cmd']=='update'){

//get the current url to convert.

$page=$_SERVER['REQUEST_URI'];


//convert the url to use the end condition from the url.

$page_name=ereg_replace("^\/+[A_Za-z]+.(php)\?(cmd)\=(update)\&(page_name)\
=",' ',$page);


// query the database to insert the stats to the correct .php page.

$query="UPDATE counter set page_name='$page_name',stats=stats+1 where page_name=
'$page_name' and stats='$stats'";

// query result.

$result=mysql_query($query) or die("query problam error");


// go to a page that the user wanted from the link.

header("location: $page_name");

//else

}else{

// goto the index page if the use goes ot this page directly.

header("location: index.php");

}

// end the flush for stopping a error header mesage.

ob_end_flush();
?>

[/code]

Share this post


Link to post
Share on other sites

×

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.