0

サイトからページとデータのリストを検索するときに、それらを最も関連性の高い順に並べるだけでなく、値も表示できるかどうか疑問に思っています。

元。販売したレモネードに関して以前に入力したデータを検索します。「時刻、気温、月など」などの複数の要因を追跡します。1 週間後の売上高を知りたい場合は、「時刻、気温、月など」に値を打ち込みます。

理論的には、入力されたすべてのデータを関連性に応じて表示できるようにしたいと考えています。これにより、以前の記録に基づいて販売するものの見積もりが示されます。何か案は?

ありがとう

4

1 に答える 1

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;
于 2013-03-30T01:48:41.490 に答える