Jump to content

[SOLVED] Increase image views count


MaDSEGA

Recommended Posts

Hi there, if someone could help, it would be much appreciated  :) I'm trying to make a script to increase the views count of an image and I just can't seem to get around it (i'm a noob  ;D ). I tried to search the forum but i cannot find any relevant solutions. Here it goes:

 

mysql_select_db();

$query_Banners = "SELECT * FROM bannners_image ORDER BY im_id DESC";

$Banners = mysql_query($query_Banners, $username) or die(mysql_error());

$totalRows_Banners = mysql_num_rows($Banners);

 

and when i click the image link, should increase the views count (im_count)

 

while ($row_Banners2=mysql_fetch_array($Banners))

 

$div_output.=<<<END

<div>

  <a href="images/{$row_Banners2['im_image']}" rel="lightbox" title="{$row_Banners2['im_description']}" target="_blank">

  <img src=images/thumbnail/{$row_Banners2['im_thumbnail']} alt="" /></a>

  <p align="middle">Views:{$row_Banners2['im_count']}</p>

</div>

END;

echo $div_output;

 

Thank you in advance  :) The page is http://www.madeofstars.org/banners.php

Link to comment
Share on other sites

I fail to see how. PHP is long done before JavaScript is called.

If the following is your PHP script:

<script type="text/javascript">
function AddCount()
{
<?php
$i++;
mysql_query("UPDATE table SET count='{$i}'");
?>
}
</script>
<img src="" onClick="AddCount()">

 

This will be the output (when you view the source code):

<script type="text/javascript">
function AddCount()
{
}
</script>
<img src="" onClick="AddCount()">

When you click the image, it'll call the AddCount javascript function but nothing else will happen.

 

Yes you can use PHP set JavaScript variables, but you cannot get JavaScript to run snippets of PHP code. The only way is AJAX.

 

PHP is parsed server side, JavaScript is client side (web browser).

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.