Log in

View Full Version : Resolved Noob Help



GreggH
03-18-2009, 09:41 AM
Hi Guys,

I'm very new to php but managing to pick it up by searching around google but there is one thing I'm having problems with and I hope someone can help me. I would imagine it would be some kinda of loop but not sure what kind.
Say i had a row in a mysql database and I wanted to echo a value from the row which in increments every time the page loads. What kinda function/loops would I need to do this? everything I have found so far echos all the rows at the same time and doesn't change every time the page is loaded.

The reason i want to do this is I have a website that i built and its being advertised on google. On this website is a form, when someone submits that form their details are passed to the users email which is in the database. What i want is every time someone fills in their details on the form those details would be passed to the next person in the database row, then once the last person in the database has been sent to, i want the loop to start over again.

Would really appreciate any help as I have been trying to figure this one out for a while now.

Thanks :)

Nile
03-18-2009, 11:17 PM
I don't completely get what your trying to do here. Can you re-explain it in differeny words please?

GreggH
03-19-2009, 09:58 AM
Hi,

Sorry I will try to explain a bit better. I have got a bit further in my attempt since i wrote that but still not got it working yet.

Lets say for example I have 50 websites which are all identical except the details that are processed in the form are sent to the owners of the 50 websites. The I have 1 advertising on google that when someone clicks on that advertising they get directed to a php processing page which in turn will redirect them to the 1st site out of 50, then when the next person clicks on the advertising they will get redirected to the 2nd site out of the 50 and that will go on until all 50 sites have been visited and then the cycle will repeat.

What i have kinda of worked out so far is that if I have a counter which I have done in a txt file which updates +1 everytime someone visits, then i have an associative array which would associate each number to a different url then redirect based on that. The problem i have been having at the moment is I cant get the count to go back to the start again it just keeps going up. This is what i have for my count so far.


<?php
$File = "counter.txt";


$handle = fopen($File, 'r+') ;


$data = fread($handle, 512) ;

if ($count = 50){
$count = 1;
fseek($handle, 0) ;
fwrite($handle, $count) ;}
else
$count = $data + 1;


print "You are visitor number ".$count;


fseek($handle, 0) ;


fwrite($handle, $count) ;


fclose($handle) ;


?>


I haven't even started with the array yet. Maybe you would know an easier way to do this.
Thanks

AlilG
03-19-2009, 11:58 AM
Hi,

Sorry I will try to explain a bit better. I have got a bit further in my attempt since i wrote that but still not got it working yet.

Lets say for example I have 50 websites which are all identical except the details that are processed in the form are sent to the owners of the 50 websites. The I have 1 advertising on google that when someone clicks on that advertising they get directed to a php processing page which in turn will redirect them to the 1st site out of 50, then when the next person clicks on the advertising they will get redirected to the 2nd site out of the 50 and that will go on until all 50 sites have been visited and then the cycle will repeat.

What i have kinda of worked out so far is that if I have a counter which I have done in a txt file which updates +1 everytime someone visits, then i have an associative array which would associate each number to a different url then redirect based on that. The problem i have been having at the moment is I cant get the count to go back to the start again it just keeps going up. This is what i have for my count so far.


<?php
$File = "counter.txt";


$handle = fopen($File, 'r+') ;


$data = fread($handle, 512) ;

if ($count = 50){
$count = 1;
fseek($handle, 0) ;
fwrite($handle, $count) ;}
else
$count = $data + 1;


print "You are visitor number ".$count;


fseek($handle, 0) ;


fwrite($handle, $count) ;


fclose($handle) ;


?>


I haven't even started with the array yet. Maybe you would know an easier way to do this.
Thanks

hey
so you want to split your paid traffic between 5 or more sites?
if yes, i write an example for u. try this


<?php
$sites_list = array(
'http://www.google.com',
'http://www.aol.com',
'http://www.yahoo.com',
'http://www.msn.com',
'http://www.meebo.com');





$counter_text_file = "counter.txt";
$present = file_get_contents($counter_text_file);
$lastone = intval($present) + 1;

$count = count($sites_list);



if($present < ($count-1))
{
//file_put_contents("counter.txt", $lastone);
$handle = fopen($counter_text_file, 'w');
fwrite($handle, $lastone);
fclose($handle);
}
else
{
//file_put_contents("counter.txt", 1);
$handle = fopen($counter_text_file, 'w');
fwrite($handle, 0);
fclose($handle);
}




print "You are being redirect to ".$sites_list[ $present ];
?>

GreggH
03-19-2009, 12:05 PM
That i perfect, thanks so much you have no idea how long i have been trying to do this...lol really appreciate your help