Click counter on dynamic images
I want to count the clicks that users do on images on my homepage. The images come out of a database table and the count should happen on the homepage itself. I managed to implement an update behavior but it updates all click within the click count field of the first recordset in the database.
So the form knows that an image has been clicked but not which one. The values for the corresponding key seems to be wrong. I'm currently using <?php echo $row_rsPromotionen['PROMID']; ?> means the value from the repeated recordset of the images. But it looks like that it's not working like this.
Repeated form:
<form method="post" name="FormPromotions" >
<?php do { ?>
<div class="container-promotion"> <a href="<?php echo $row_rsPromotionen['LinkToURL']; ?>"><input type="image" name="<?php echo $row_rsPromotionen['PROMID']; ?>" id="<?php echo $row_rsPromotionen['PROMID']; ?>" src="<?php echo $row_rsPromotionen['PromotionBanner']; ?>" width="775" height="225" alt="<?php echo $row_rsPromotionen['Promotion']; ?>" title="<?php echo $row_rsPromotionen['Promotion']; ?>"/></a></div>
<?php } while ($row_rsPromotionen = mysql_fetch_assoc($rsPromotionen)); ?>
</form>
Update code:
<?php
// WA DataAssist Update
if (($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST)) // Trigger
{
$WA_connection = $ullrich_db;
$WA_table = "promotionen";
$WA_redirectURL = "".$row_rsPromotionen['LinkToURL'] ."";
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = false;
$WA_indexField = "PROMID";
$WA_fieldNamesStr = "Clicks";
$WA_fieldValuesStr = "".$row_rsPromotionen['Clicks']+1 ."";
$WA_columnTypesStr = "none,none,NULL";
$WA_comparisonStr = "=";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode($WA_AB_Split, $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_where_fieldValuesStr = "".$row_rsPromotionen['PROMID'] ."";
$WA_where_columnTypesStr = "none,none,NULL";
$WA_where_comparisonStr = "=";
$WA_where_fieldNames = explode("|", $WA_indexField);
$WA_where_fieldValues = explode($WA_AB_Split, $WA_where_fieldValuesStr);
$WA_where_columns = explode("|", $WA_where_columnTypesStr);
$WA_where_comparisons = explode("|", $WA_where_comparisonStr);
$WA_connectionDB = $database_ullrich_db;
mysql_select_db($WA_connectionDB, $WA_connection);
@session_start();
$updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues, $WA_where_comparisons );
$WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
Thanks for any help on this.