2011-02-06 5 views
0

이미지를 클릭 한 횟수를 세는 방법이 있습니까? 그리고 이미지가 클릭되면 표시됩니까?이미지 클릭 카운터

현재 데이터베이스에서 임의의 이미지를 가져 와서 가장 많이 클릭 된 이미지를 표시하려고합니다.

<html> <body> 

<div style="float:left"> <?php // Connect to the database mysql_connect ('localhost', 'root') ; mysql_select_db ('links'); 

// Number of images $num_displayed = 1 ; 

// Select random images from the database $result = mysql_query ("SELECT * FROM links ORDER BY RAND() LIMIT $num_displayed"); 

// For all the rows that are selected while ($row = mysql_fetch_array($result)) 

// Display images { echo "<a href=\"".$row["link"]."\"><img src=\"".$row["image"]."\" border=0 alt=\"".$row["text"]."\"></a>"; } ?> </div> 

<div style="float:left; margin-left:100px"> <?php include("image2.php"); ?> 

</div> </body> </html> 

감사합니다. body 태그에서

<script type="text/javascript"> 
    var count = 0; 
    function changevar(){ 
      count = count + 1; 
     if (count == 3) { 
      alert('Done'); 
     } 
    } 
     </script> 

: head 태그에

:

+0

IP가 라우터 뒤에있는 사람들을 나타낼 수 있음을 명심하십시오. 동일한 IP가 다른 사람들이 당신의 이미지를 클릭하는 것을 나타낼 수 있습니다. –

+0

'INCR' – Alfred

답변

0

은 선택

CREATE TRIGGER `database_name`.`trigger_name` BEFORE SELECT INSERT ON 
    `database_name`.`images_table_name` FOR EACH ROW 
BEGIN 
    UPDATE 
     `database_name`.`images_table_name` 
    SET 
     `database_name`.`images_table_name`.`counter` = `database_name`.`images_table_name`.`counter` + 1 
    WHERE 
     `database_name`.`images_table_name`.`id` = NEW.`id`; 
    END$$ 
을 계산하는 이미지 테이블에 트리거를 생성

Perfo 카운터 필드로 주문하는 querys rm. 클릭을 등록하려면

이 같은 두 번째 필드에 대한 업데이 트를 quering 클릭 추적 구현 '클릭'

0

이 사용하는 자바 스크립트 작업을 수행 할 수 있습니다

<img src="image.png" onClick="changevar()"/> 
+0

을 사용하여 쉽게 redistogo.com을 사용하여 이것을 쉽게 달성 할 수 있습니다. 번호를 표시합니다. –

0

어떻게 이미지가 표시 될 때마다 계산 어떻습니까? 이것은 이미지 앨범 뷰어가 작동하는 방식에서 다른 이미지가없는 경우에만 옵션입니다.

이미지를 렌더링하려면 PHP를 사용하고이 이미지가 클릭되거나 표시되는 횟수를 증가시키는 작은 스크립트를 실행하십시오. 또는 이미지가 표시 될 때마다 항목을 만들어 이미지, last_view, ip, count 및/또는 referrer (작동하는 경우, 테스트되지 않음)와 같은 재미있는 정보를 훨씬 많이 저장할 수 있습니다. IP를 기록하면 이미지를 검토 한 횟수를 보여주는 고유 한 뷰를 추적 할 수 있습니다. 이것은 구현 방법에 따라 다릅니다. 당신이 문제와 이미지가 제대로 표시되어있는 경우

$name = trim($_GET['img']); 
if (!isset($_GET['img'] || empty($name)) { 
    // Check url var wasn't omitted or typed incorrectly. 
    die("Image not specified."); 
} 

// This is just an example path. It would be a good idea to specify a path 
// like this to ensure that people don't try and use it to display files 
// that you wouldn't want them too. 
//eg. images you don't want to keep records of. 
$image = "/images/$name"; 

$date = time(); 
$ip = $_SERVER['REMOTE_ADDR']; 
$ref = $_SERVER['HTTP_REFERER']; 

if (!file_exists($image)) { 
    // Ensure that something exists at $image 
    die("Invalid image."); 
} 

$f = fopen($image, 'r'); 
if (!$f) { 
    // Make sure that the contents of the file can be opened. 
    die("Unable to open image."); 
} 

$info = @imagegetsize($image); 
if (!$info) { 
    // This is to make sure that the $image contains a path 
    // to an image not just a regular file. 
    die("Invalid image type."); 
} 

Header("Content-type: {$info['mime']}"); 
echo fread($f, filesize($image)); 

fclose($f); 

/**************** 
* Script for saving image 'click' information. 
***************/ 

exit; 

표시이

<img src="/image.php?img=example.png" /> 

같은 이미지는 오류를 확인하기 위해서는 브라우저의 경로를 엽니 다.