MySQL version 3.23.58
Table ImportedPaidLeads looks like:
Lender | SubmitDate | ssn
LenderOne 2005-03-13 550-55-5555
LenderOne 2005-03-13 550-55-5005
LenderOne 2005-03-15 550-55-5215
LenderOne 2005-03-15 550-55-5134 ---Dups
LenderOne 2005-03-15 550-55-5134 ---Dups
LenderOne 2005-03-17 550-55-5005
LenderOne 2005-03-17 550-55-5215 ---Dups
Table temp_table looks like
ssn
550-55-5555
550-55-5005
550-55-5215
550-55-5214
550-55-5212
550-55-5211
Should be no dups in table_temp as i use distinct to grab it from one dbase and put it into my temp_table see full code below:
Code:
<?php
session_start();
$MyArray = "";
$export_date = $_POST['export_date'];
session_register ("export_date");
$export_date2 = $_POST['export_date2'];
session_register ("export_date2");
define('db_host','localhost');
define('db_user','****');
define('db_pass','****');
define(db_link, mysql_connect(db_host,db_user,db_pass));
define('db_name',''.$_SESSION['db_name'].'');
mysql_select_db(db_name);
//grab ssn numbers from long_form table no dups
$sql = "SELECT DISTINCT ssn_part_1, ssn_part_2, ssn_part_3 FROM long_form WHERE signup_date BETWEEN '".$_POST['export_date']."' AND '".$_POST['export_date2']."'";
$res = mysql_query($sql);
$total_rows = mysql_num_rows($res);
// loop the recordset create ssn array
while ($article = mysql_fetch_assoc($res)) {
$MyArray[] .= $article['ssn_part_1'] . "-" . $article['ssn_part_2'] . "-" . $article['ssn_part_3'];
}
//connect and make temp table
$hostname_main = "localhost";
$database_main = "******";
$username_main = "****";
$password_main = "*****";
$main = mysql_pconnect($hostname_main, $username_main, $password_main) or die(mysql_error());
mysql_select_db($database_main, $main);
$temp_table = "CREATE TEMPORARY TABLE `temp_table` (`ssn` varchar(15) default NULL) TYPE=MyISAM";
mysql_query($temp_table);
//insert ssn array into temp table
foreach ($MyArray AS $value) {
$sql2 = "INSERT INTO temp_table (ssn) VALUES ('".$value."')";
mysql_query ($sql2) or die(mysql_error());
}
//compare temp_table and paidleads table and select matching data from paidleads table to get leads
$sql2 = "SELECT ImportedPaidLeads.SubmitDate, count(DISTINCT temp_table.ssn) as groupcount from ImportedPaidLeads, temp_table WHERE ImportedPaidLeads.ssn = temp_table.ssn AND ImportedPaidLeads.SubmitDate BETWEEN '".$_POST['export_date']."' AND '".$_POST['export_date2']."' group by SubmitDate";
mysql_query ($sql2) or die(mysql_error());
$res2 = mysql_query($sql2);
$sql3 = "SELECT count(DISTINCT temp_table.ssn) as allleads from ImportedPaidLeads, temp_table WHERE ImportedPaidLeads.ssn = temp_table.ssn AND ImportedPaidLeads.SubmitDate BETWEEN '".$_POST['export_date']."' AND '".$_POST['export_date2']."'";
mysql_query ($sql3) or die(mysql_error());
$res3 = mysql_query($sql3);
$showleads = mysql_fetch_assoc ($res3);
$sql4 = "SELECT count(DISTINCT ssn) as allapps from temp_table"; //get the ammount of products in the db
mysql_query ($sql4) or die(mysql_error());
$res4 = mysql_query($sql4);
$showapps = mysql_fetch_assoc ($res4)
?>
The i use this to display the result:
Code:
<p align="center" class="Content">For the period <?php echo $export_date ?> to <?php echo $export_date2 ?></p>
<p align="center" class="Content">There have been <?php echo $showapps['allapps']; ?> apps <br>
<?php while ($showleads = mysql_fetch_assoc ($res2))
{ ?>
<?php echo $showleads['SubmitDate']; ?>
<?php echo $showleads['groupcount']; ?>
<? php }
$dtemp_table = "DROP TABLE temp_table ";
mysql_query($dtemp_table);
mysql_free_result($res4);
mysql_free_result($res);?>
Also, this seems slow, and sometime i get doubled results meaning, it will count everything twice.
Thx for the help i owe ya
Z