PDA

View Full Version : download counter And extra info question


paul.casbourne361959
05-07-2009, 08:21 AM
Hi, I hope I've managed to provide enough info/context around my question.

I'd like to insert extra information as well as the download count, in a table. My objective is to capture the download history of logged in users.

The MySQL table is setup with the fields "idx, user_id, filename, date, file_count". (my additional information requirement)

However, the DFP wizards default behaviour appears to only insert the download count value into a specified table - no options to insert addiional info.

Does anyone know how to add the additional information?
Unless i've overlooked something, the solution recipe does not provide anything I can use.

Any help appreciated. Thaks, Paul.

Ray Borduin
05-11-2009, 06:46 AM
If you use DataAssist to do the insert you should be able to insert into whatever columns you want to. The DFP wizard will only help upload and download the files you still need DataAssist to manipulate the database.

Heckie
07-08-2009, 03:01 AM
I've set up my download counter and it works great. The only problem I have is that I need to refresh the page to see the updated count.

How do I get the form to refresh the page with the updated count value?

At the moment I have this (orderdetails.php it the page with the download button):

<form action="orderdetails.php?ID=<?php echo $row_WADAmusic['DetailOrderID']; ?>" method="post" name="downloadform" id="downloadform">

Ray Borduin
07-08-2009, 07:44 AM
Make sure your update code is above your recordset.

Heckie
07-08-2009, 08:34 AM
Not sure what you mean by update code? Can you give me an example?

At the moment the form containing the download button just posts with no action:

<form method="post" name="downloadform" id="downloadform">
<input name="download" type="image" id="download" value="Download" src="../images/design/download2.gif" alt="Download" />
</form>

Ray Borduin
07-08-2009, 08:54 AM
I am referring to the code above the <html>. What does that look like?

Heckie
07-08-2009, 09:36 AM
Here is the complete php section of my orderdetails pae:

<?php
//WA eCart Include
require_once("../WA_eCart/HeckieCart_PHP.php");
?>
<?php require_once('../Connections/connHeckie.php'); ?>
<?php
$HeckieCart->GetContent();
?>
<?php require_once("../WA_DigitalFilePro/HelperPHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
?>
<?php
$maxRows_WADAorderdetails = 1000;
$pageNum_WADAorderdetails = 0;
if (isset($_GET['pageNum_WADAorderdetails'])) {
$pageNum_WADAorderdetails = $_GET['pageNum_WADAorderdetails'];
}
$startRow_WADAorderdetails = $pageNum_WADAorderdetails * $maxRows_WADAorderdetails;

$WADAID_WADAorderdetails = "-1";
if (isset($_GET['ID'])) {
$WADAID_WADAorderdetails = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}
mysql_select_db($database_connHeckie, $connHeckie);
$query_WADAorderdetails = sprintf("SELECT * FROM orderdetails WHERE DetailOrderID = %s ORDER BY DetailItemName ASC", GetSQLValueString($WADAID_WADAorderdetails, "int"));
$query_limit_WADAorderdetails = sprintf("%s LIMIT %d, %d", $query_WADAorderdetails, $startRow_WADAorderdetails, $maxRows_WADAorderdetails);
$WADAorderdetails = mysql_query($query_limit_WADAorderdetails, $connHeckie) or die(mysql_error());
$row_WADAorderdetails = mysql_fetch_assoc($WADAorderdetails);

if (isset($_GET['totalRows_WADAorderdetails'])) {
$totalRows_WADAorderdetails = $_GET['totalRows_WADAorderdetails'];
} else {
$all_WADAorderdetails = mysql_query($query_WADAorderdetails);
$totalRows_WADAorderdetails = mysql_num_rows($all_WADAorderdetails);
}
$totalPages_WADAorderdetails = ceil($totalRows_WADAorderdetails/$maxRows_WADAorderdetails)-1;

$colname_rsOrder = "-1";
if (isset($_GET['ID'])) {
$colname_rsOrder = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}
mysql_select_db($database_connHeckie, $connHeckie);
$query_rsOrder = sprintf("SELECT *, DATE_FORMAT(OrderDate, '%%W %%D %%M %%Y %%r') as OrderDate FROM orders WHERE OrderID = %s", GetSQLValueString($colname_rsOrder, "int"));
$rsOrder = mysql_query($query_rsOrder, $connHeckie) or die(mysql_error());
$row_rsOrder = mysql_fetch_assoc($rsOrder);
$totalRows_rsOrder = mysql_num_rows($rsOrder);

$colname_rsDownloadFile = "-1";
if (isset($_POST['fileID'])) {
$colname_rsDownloadFile = (get_magic_quotes_gpc()) ? $_POST['fileID'] : addslashes($_POST['fileID']);
}
mysql_select_db($database_connHeckie, $connHeckie);
$query_rsDownloadFile = sprintf("SELECT * FROM orderdetails WHERE DetailsID = %s", GetSQLValueString($colname_rsDownloadFile, "int"));
$rsDownloadFile = mysql_query($query_rsDownloadFile, $connHeckie) or die(mysql_error());
$row_rsDownloadFile = mysql_fetch_assoc($rsDownloadFile);
$totalRows_rsDownloadFile = mysql_num_rows($rsDownloadFile);?>
<?php
WA_DFP_SetupDownloadStatusStruct("WA_DownloadResult1");
if($_SERVER["REQUEST_METHOD"] == "POST"){
WA_DFP_DownloadFile("WA_DownloadResult1", "../downloads/", "".$row_rsDownloadFile['DetailDownloadFile'] ."", "[FileName]", 1, $database_connHeckie, $connHeckie, "orderdetails", "DetailsID", "".$row_rsDownloadFile['DetailsID'] ."", "DetailDownload");
}
?>
<?php
$queryString_WADAorderdetails = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_WADAorderdetails") == false &&
stristr($param, "totalRows_WADAorderdetails") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_WADAorderdetails = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_WADAorderdetails = sprintf("&totalRows_WADAorderdetails=%d%s", $totalRows_WADAorderdetails, $queryString_WADAorderdetails);
?>
<?php
// WA eCart Redirect
if ($HeckieCart->redirStr != "") {
header("Location: ".$HeckieCart->redirStr);
}
?>

Ray Borduin
07-08-2009, 09:47 AM
Where is the download counter incremented? I thought I would see some sort of update statement on the page?

How do you display the download count?

Heckie
07-08-2009, 09:52 AM
I have basically just placed a bit of dynamic text followed by / 5 (<?php echo $row_WADAorderdetails['DetailDownload']; ?> / 5)

Ray Borduin
07-08-2009, 11:21 AM
When do you increment DetailDownload?

Heckie
07-09-2009, 01:19 AM
I increment DetailDownload in the orderdetails table after the customer presses the download button, but I need to refresh my page to see the update.

What i would like to do is limit the customer to 1 download, then the button (or functionality) disappears straight away…

Here's the SQL:

<?php
WA_DFP_SetupDownloadStatusStruct("WA_DownloadResult1");
if($_SERVER["REQUEST_METHOD"] == "POST"){
WA_DFP_DownloadFile("WA_DownloadResult1", "../downloads/", "".$row_rsDownloadFile['DetailDownloadFile'] ."", "[FileName]", 1, $database_connHeckie, $connHeckie, "orderdetails", "DetailsID", "".$row_rsDownloadFile['DetailsID'] ."", "DetailDownload");
}
?>

Ray Borduin
07-09-2009, 07:20 AM
OK, I'm finally understanding. Sorry. I forgot the increment option was part of the download.

Your only option would be to add the number to a span or div that you could update with javascript. Since you want to update the page without refreshing, the only option is to use script. The script should be pretty easy though.

Store the number in it's own div or span. Then read the innerHTML of the div or span with a parseInt() to convert the value to a number and store it as a variable. Increment it by one with ++ and reset the innerHTML to the incremented value.

Heckie
07-09-2009, 07:41 AM
I need (if possible) the download trigger to automatically refresh the page with the updated DetailDownload - let me explain why.

My store also sells music books, so on my order details page I have 3 tables, each using its own recordset.

The first is 'music downloads (rsMusic)' and looks for items that have 'DetailCategory = 1 AND DetailDownloads < 1''

The second is 'music downloaded (rsDownloaded)' and looks for items that have 'DetailCategory = 1 AND DetailDownloads = 1'

The third is 'books (rsBooks)' and looks for items that has 'DetailCategory = 2'

So once someone has download the file, I would like the page to refresh with the item moving from table 1 to table 2 which has no download option…

Ray Borduin
07-09-2009, 07:46 AM
OK... try adding javascript to the onClick event of the button that initiates the download.

Something like:

onclick="setTimeout('document.location.href=document.locati on.href',1000)"

that should give it one second... which is hopefully enough time to initiate the download and increment the database, then it refreshes the page.

Heckie
07-09-2009, 08:06 AM
It works!!! Thanks for all your help - everything seems to work as I would like!!

lejohnson01403530
04-09-2010, 09:48 AM
I need to do something very similar to this. However, I'm not clear on the java script. Do you leave the script exactly as shown (onclick="setTimeout('document.location.href=document.locati on.href',1000)") or do you replace document.location with something? If so, what?

I tried adding the onclick statement, as is, to my download button and I see no difference in behavior. Nothing is updated on the page.

lejohnson01403530
04-09-2010, 10:37 AM
Nevermind the last post. I got the script to start working. However, now the download file behavior doesn't get triggered. If I remove the onclick script, the download works again. Any ideas?

Jason Byrnes
04-13-2010, 08:47 AM
try extending the time out from 1000 to 3000:
onclick="setTimeout('document.location.href=document.locati on.href',3000)"