Hello,
I have got 4 tables in the same database. The name of the tables are [B]table03[B]table04[B]table05 [B]table06[B]price[B]full_add
So assuming that my keywords were Toyota, Honda, Mercedes and BMW(keyed in as 1 keyword per line in the form), the end result should display something like this:-
[B]Median Price from table03
Toyota – $3883
Honda – $356
Mercedes – $7865
BMW – $1347
[B]Median Price from table04
Toyota – $7688
Honda – $4312
Mercedes – $8709
BMW – $1254
[B]Median Price from table05
Toyota – $8776
Honda – $3445
Mercedes – $8778
BMW – $1223
[B]Median Price from table06
Toyota – $6578
Honda – $5445
Mercedes – $545
BMW – $12548
What I’ve already done succesfully is to query the database based on 1 record per line. My code is below.
The part that I do not know how to code is as follows:-
1. A join query to query all tables at one go.
2. To calculate the median 4 times(once for each table) & display the results like the sample above.
Please show me how to write the code. Thank you for your help.
[code=php]<?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);
$query1=”SELECT price FROM table WHERE “.$email_str . $limit;
$result1=mysql_query($query1);
}
/* Median calculation for the price. */
$thearray=array();
while ( $row=@mysql_fetch_array($result1,MYSQL_NUM) ) {
$thearray[]=$row[0];
}
$num0=count($thearray);
if ($num0 % 2) {
$median1 = $thearray[floor($num0+1)/2 – 1];
} else {
$median1 = ($thearray[$num0/2] + $thearray[$num0/2 – 1]) / 2;
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<form name=”ftest” action=”<?= $_SERVER[‘PHP_SELF’]; ?>” method=”post”>
<textarea name=”femail”></textarea><br />
<input type=”submit” name=”Submit” value=”Send” />
</form>
<table width=700 border=1 height=”0″ style=”border-collapse: collapse” bordercolor=”#111111″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td style=”border-style: solid; border-width: 1″ bgcolor=”#99CCCC” align=”left” width=”350″><b>
<div align=”center”><font size=”3″ face=”Arial, Helvetica, sans-serif”><? echo “Median Price – RM<font color=’#FF33cc’> $median1 </font>”; ?></font></div></td>
</tr>
</table>
</body>
</html>