Quote:
|
What's the point of having 4 tables with the exact same structure?
|
Good question & thank you for asking. When I initially created everthing, the database sizes where so huge that I broke them down into 4 different tables representing 4 different years.
At this stage, I've got everything working except the median calculation is not looping through the search results. Therefore, instead of getting a result like
Median Price from table03
Toyota - $3883
Honda - $356
Mercedes - $7865
BMW - $1347
I am getting a result like
Median Price from table03
Toyota - $3883
Honda - $3883
Mercedes - $3883
BMW - $3883
My code is below & I trust that you can edit it for me. Thanks.
PHP Code:
<?php
$limit = "LIMIT 0,100000";
mysql_connect ("$host","$username","$password");
mysql_select_db($database) or die( "Where's the database man?");
if(isset($_POST['Submit'])){
$emails=explode("\n", str_replace("\r", "", $_POST['femail']));
$email_r=array();
foreach($emails as $e){
$email_r[]="full_add LIKE '%".mysql_escape_string($e)."%'";
}
$email_str=implode(' OR ',$email_r);
for($j = 3; $j <= 6; $j++)
{
echo '<b>Median Price from table0'.$j.'</b><br>';
for($i = 0; $i < sizeof($emails); $i++)
{
$query = "SELECT price FROM table0$j WHERE $email_str ORDER BY price DESC $limit";
$result = mysql_query($query);
/* The median calculation starts here. It's not looping through the
search results & I don't know how to solve this. Please help me. */
$thearray=array();
while ( $row=@mysql_fetch_array($result,MYSQL_NUM) ) {
$thearray[]=$row[0];
}
$num0=count($thearray);
if ($num0 % 2) {
$median = $thearray[floor($num0+1)/2 - 1];
} else {
$median = ($thearray[$num0/2] + $thearray[$num0/2 - 1]) / 2;
}
/* The median calculation ends here. */
echo $emails[$i].' - $'.$median.'<br>';
}
}
}
?>
<form name="ftest" action="<?= $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="femail"></textarea><br />
<input type="submit" name="Submit" value="Send" />
</form>