• 0

PHP Problem


Question

if (isset($_POST["from"])) {

$date_from = strtotime( $_POST['from'] );
$date_to = strtotime( $_POST['to'] );

// Format the timestamps to valid MySQL date strings: "YY-MM-DD HH:MM:SS" (in PHP: "Y-m-d H:i:s")
$date_from_mysql = date('Y-m-d 00:00:01', $date_from);
$date_to_mysql = date('Y-m-d 23:59:59', $date_to);

$result = mysql_query("SELECT * FROM binfo_britinfo.newafilcomp WHERE id=$cid LIMIT 1")or die(mysql_error());
$row = mysql_fetch_array($result); 

echo "<h4>".$row["cname"]." - Revenue Report (<a href=\"pdf.php?from=".$_POST['from']."&to=".$_POST['to']."&cid=".$cid."\">Generate PDF</a>)</h4>"; 
echo "<p><b>Date:</b> ".$_POST['from']." - ".$_POST['to']."</p>";
echo "<hr>";

echo '<table width="650" cellpadding="2" cellspacing="0">';
echo '<tr><td width="150"><b>Page</b></td><td width="100"><b>This Month (Clicks)</b></td><td width="100"><b>Earnings</b></td></tr>';
$start = number_format(0, 2, '.', '');
$getcompanies = mysql_query("SELECT aid, COUNT(aid) FROM binfo_britinfo.newafilclick WHERE datetime BETWEEN '".$date_from_mysql."' AND '".$date_to_mysql."' GROUP BY aid ORDER By COUNT(aid) DESC")or die(mysql_error());
while($row = mysql_fetch_assoc($getcompanies))
{
echo '<tr><td><a href="adclicks.php?id='.$row["aid"].'">'.getpgname($row["aid"]).'</a></td><td>'.$row['COUNT(aid)'].'</td><td>?'.earnings($row["aid"],$row['COUNT(aid)']).'</td></tr>';
$num = earnings($row["aid"],$row['COUNT(aid)']);
$total = $start + $num;
$start = $total;
$total = number_format($total, 2, '.', '');
}
echo '<tr colspan="3"><td colspan="3" align="right">Total Earnings: ?'.$total.'</td></tr>';

echo '</table>';
}

else
{

}

This code loads up the clicks from adverts from my database, it works fine if I set any date apart from the 31st of Jan, If i set 1st - 30th jan it loads everything up, if i set it to 1st - 31st jan, it doesn't finish the while loop, the total earnings don't get displayed so i'm guessing it stops before then, any reason why on that date it would just stop?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Less guessing, more debugging!

I can't really help you without knowing what the output looks like and if the database is outputting anything at all.

Can you show us the output of $row?

var_dump($row);

Right after the first $getcompanies write

$row = mysql_fetch_assoc($getcompanies);
var_dump($row);
while($row)
{
...//rest of code inside of while loop goes here
}

Also, have you tried running the query in your database by itself with a 3rd party tool like phpmyadmin or straight from the mysql prompt?

SELECT aid, COUNT(aid) FROM binfo_britinfo.newafilclick WHERE datetime BETWEEN '2011-1-1 00:00:01' AND '2011-1-31 23:59:59' GROUP BY aid ORDER By COUNT(aid) DESC ;

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.