I am facing problem in updating the number of times the link is clicked. The function to update links works fine in a new file. But when I include it in the link counter file, this function is not working.i.e. not updating the number of times a link is clicked. here is the code:

<?php

$con=mysql_connect("localhost","arslan","arslan");	//conecting to database
if(!$con)

{

die("not conect".mysql_error());
}

mysql_selectdb("arslan",$con);	// selecting database


//taking url of download file

$urlForFile="SELECT * FROM `test` WHERE `links` LIKE '%dro%'";

$queryForFIleUrl=mysql_query($urlForFile);


while($row=mysql_fetch_array($queryForFIleUrl))		// geting complete url of download file
{

$orignalUrl=$row['links'];		// strong value for url in variable

}


//geting value from download link, and passing it to counter function and chaning header to url of download file.





echo "Current count:" .counter(). " <a href='/count.php?action=increment' target='_blank'>Download</a>";

if (isset($_GET['action']) == 'increment')
{
    
	updata();
	header("Location:$orignalUrl");
}


function updata()

{

mysql_query("update test set counts = counts + 1 where links like '%tes%'");

}




//counter function

function counter()
{


 $geting="SELECT `counts` FROM `test` WHERE `links` LIKE '%tes%'";		//queries local to function

$geting_counts=mysql_query($geting);


		while($row=mysql_fetch_array($geting_counts))
			{

				
				echo $row['counts'];


			}
	

}




?>

OMG your running one row in while loop :S ~~

function counter()
{
$result = mysql_query("SELECT `counts` FROM `test` WHERE `links` LIKE '%tes%'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // use return best.

}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.