2013-03-30 45 views
0

想知道是否有可能,當您從網站搜索頁面和數據列表時,如果您不僅可以在最相關的第一個排序它們,而且還可以顯示一個值。附加搜索結果/註釋

ex。您搜索您之前輸入的有關您銷售的檸檬水的數據。你跟蹤多種因素,如「時間,溫度,月份等」。你想知道一週後你會賣多少錢,所以你可以將價值打入「一天中的時間,溫度,月份等等」。

從理論上講,我希望能夠根據相關性提出所有輸入的數據,並根據以前的記錄向您顯示您將銷售的產品的估算。有任何想法嗎?

謝謝

回答

0

這將需要一個算法。我不會寫所有的代碼,但我不介意給一些指導:)。 獲取數據的html與設置數據的html相同,除了它會調用一個單獨的.php腳本。

以下示例可用於指導。它僅使用溫度來計算預測銷售額:

//get todays temperature from form, and query database for all temperatures 
$todaysTemp = $_POST['temperature']; 
$tempRange = 20; //each temperature in the table must be within this range of todaysTemp to be included in calculation 
$result = $connection->query("SELECT temperature, sales FROM myTable"); 

//calculate average temperature by adding this temp to total, then diving by total rows included 
$temp_sales_array = array(); 
foreach($result as $row){ 
    if(abs($todaysTemp - $row['temperature']) < tempRange){ 
     $temp_sales_array[$row['temperature']] = $row['sales']; 
    } 
} 

//calculate predicted sales, by getting array value thats closest to todays temperature 
$closest=key($temp_sales_array[0]); 
foreach($temp_sales_array as $row){ 
    if(abs($todaysTemp - key($row)) < closest){ 
     closest = key($row); 
     $predicted_sales = $row; 
    } 
} 

//show predicted sales 
echo $predicted_sales;