ballhogjoni Posted June 10, 2008 Share Posted June 10, 2008 hey everyone I have this script that is supposed to pull the number of rows based on a date range. The problem I am having is that it only pulls one row, when I know that there are multiple rows. My code: <?php $date2 = date("Y-m-d",mktime(0, 0, 0, $m1, $d1, $y1)); $date1 = date("Y-m-d",mktime(0, 0, 0, $m2, $d2, $y2)); include "action.php";//this script includes the functions below echo "<br>Sales: ".sale(strtotime($date2),strtotime($date1)); echo "<br>Leads: ".lead(strtotime($date2),strtotime($date1)); ?> <?php function sale($d2,$d1) { $result = mysql_query("SELECT id FROM offers WHERE mediaCompany = '".strtolower($_SESSION['myusername'])."' AND typeOfLead = 'sale' AND orderDate BETWEEN '".$d2."' AND '".$d1."'") or die(mysql_error()); $count = mysql_num_rows($result); return $count; } function lead($d2,$d1) { $result = mysql_query("SELECT id FROM offers WHERE mediaCompany = '".strtolower($_SESSION['myusername'])."' AND typeOfLead = 'lead' AND date BETWEEN '".$d2."' AND '".$d1."'") or die(mysql_error()); $count = mysql_num_rows($result); return $count; } ?> Link to comment https://forums.phpfreaks.com/topic/109621-solved-php-mysql-query-gone-wrong/ Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 Have you tried not using the function and only doing just 1 of the queries? Link to comment https://forums.phpfreaks.com/topic/109621-solved-php-mysql-query-gone-wrong/#findComment-562308 Share on other sites More sharing options...
Asheeown Posted June 10, 2008 Share Posted June 10, 2008 <?php function sale($d2,$d1) { $result = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM offers WHERE mediaCompany = '".strtolower($_SESSION['myusername'])."' AND typeOfLead = 'sale' AND orderDate BETWEEN '".$d2."' AND '".$d1."'") or die(mysql_error()); $count = mysql_result($result, 0); return $count; } function lead($d2,$d1) { $result = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM offers WHERE mediaCompany = '".strtolower($_SESSION['myusername'])."' AND typeOfLead = 'lead' AND date BETWEEN '".$d2."' AND '".$d1."'") or die(mysql_error()); $count = mysql_result($result, 0); return $count; } ?> Try that, I didn't test it so i might have added or forgotten a ( or ), post back with the feedback Link to comment https://forums.phpfreaks.com/topic/109621-solved-php-mysql-query-gone-wrong/#findComment-562313 Share on other sites More sharing options...
ballhogjoni Posted June 10, 2008 Author Share Posted June 10, 2008 I figured it out. I was taking to many steps. I had this in my code date("Y-m-d",mktime(0, 0, 0, $m2, $d2, $y2));. The date function didn't need to be there becasue I am saving the date as the unix timestamp using time(). So basically the query was reading the wrong date and therefore not giving me the result i wanted. Link to comment https://forums.phpfreaks.com/topic/109621-solved-php-mysql-query-gone-wrong/#findComment-562364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.