2013-03-30 12 views
0

궁금한게 있다면, 사이트에서 페이지 및 데이터 목록을 검색 할 때 가장 관련있는 순서로만 주문할 수 있고 값을 표시 할 수 있는지 궁금합니다.추가 검색 결과/노트 검색

ex. 당신은 당신이 판매 한 레모네이드와 관련하여 이전에 입력 한 데이터를 검색합니다. 당신은 "시간, 온도, 월 등의 시간"과 같은 여러 요소를 추적합니다. 당신은 일주일 후에 얼마만큼 팔릴지를 알고 싶어합니다. 그래서 당신은 "시간, 온도, 달 등의 시간"에 가치를 부여합니다.

이론적으로 나는 관련성에 따라 입력 된 모든 데이터를 가져올 수 있기를 희망하며 이전 레코드를 기반으로 판매 할 것으로 추정되는 것을 보여줍니다. 어떤 아이디어?

감사합니다.

답변

0

알고리즘이 필요합니다. 나는 모든 코드를 쓰지 않을 것이다. 그러나 나는 약간의 지침을주는 마음을 가지지 않을 것이다 :). 데이터를 가져 오는 html은 별도의 .php 스크립트를 호출한다는 점을 제외하면 데이터를 설정하는 html과 동일합니다.

다음 예는 지침으로 사용할 수 있습니다. 계산 된 예상 판매량에 온도만을 사용합니다.

//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;