Hi,
Ok first off ive been racking my brain trying to make this work for a good day now, im nearly at my wits end lol....
So basically I have a dynamic list of objects pulled in from my database. I then have a hit counter that records the amount of hits for each object when a user clicks on them. The counter code stuff is located on a separate php file for these purposes im calling..thecode.php.
Then in my main file i have this statement to pull out the objects from the database. The a href for each image is then the counter script...
// rest of code
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$therow = $row['charid'];
echo '<tr><td align="left" class="thumb"><a href="thecode.php?link='. $therow .'" target"_self"><img border="0" src="thumbs/' . $row['charid'] . '/thumb.JPG" /></a></td>
<td align="left" class="thumb2"><strong>' . $row['name'] . '</strong><br />' . $row['count'] . '<br />' . $row['dr'] . '</td></tr>
';
}
// rest of code
The code itself works fine, but when you click on an image the content is replaced by just a '>'. For the mean time i put a meta refresh at the bottom just to get it back to the proper page with the updated hit totals. Of course this is not good because u still get a flash of that stupid >
I have tried putting the counter code within my main file but I could not get it to record the hits properly for each object, it just stuck at 1.
So could anyone at all help me out either my sorting it out so that it doesnt show the > and just automatically updates the page, or can someone help me put the counter code within my main file.
Here is the link to the site where i am developing it on. Note it has been majorly stripped down for the purposes of this forum post.
http://www.enhanced-media.com/vp
This is the code within 'thecode.php'...
<?php
// database details
function dbinsans($text) {
$text = strip_tags ($text, "");
$text = str_replace(chr(10),"",$text);
$text = str_replace(chr(13), "<br>", $text);
$text = str_replace("'","*",$text);
$text = str_replace("'","*",$text);
$text = addslashes($text);
return($text);
}
$link=dbinsans($_GET['link']);
$db = mysql_connect("$dbHost","$dbUser","$dbPass");
mysql_select_db($dbname,$db);
$requete = "SELECT * FROM characters WHERE char_id='$link'";
$result3 = mysql_query ($requete,$db);
#Should return only one value, our link if it exists
$article = mysql_fetch_object($result3);
#Gives an object with our row back
$count = $article->count + 1;
#Gets and adds one to counter variable
$sql = "UPDATE characters SET count='$count' WHERE char_id='$link'";
#Updates count
mysql_query($sql, $db);
#Queries the database and updates the count at ID.
mysql_free_result($result3);
exit();
?>
Thank you ever so much in advance for any help you can give.
🙂 Martin