第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用日期范圍從表中查詢多個(gè)詳細(xì)信息來(lái)獲取數(shù)據(jù)?

如何使用日期范圍從表中查詢多個(gè)詳細(xì)信息來(lái)獲取數(shù)據(jù)?

PHP
慕桂英546537 2023-07-15 15:48:20
我已經(jīng)能夠使用表下方的代碼從此表中獲取多個(gè)詳細(xì)信息......我知道該表看起來(lái)很奇怪,但這是客戶端提供的可用數(shù)據(jù)表。    id  | class  | gender |         e1              |      e2                     |                d1                     |           d2            ----------------------------------------------------------------------------------------------------------------------------------------------------------------    1   | class1   |  male  | ,first, first, first    | ,first, first, first        |  , 2019-12-24,2019-12-24,2019-12-24    | ,2019-12-04,2019-11-21,2019-11-20 |      2   | class2   | female | ,second, second, second |  ,second, second, second    |  ,2019-12-04,2019-11-21,2019-11-20      |  , 2019-12-20,2019-12-20,2019-12-20     3   | class3   |  male  | ,first, first, first    | ,third, third, third        |  ,2019-12-06,2019-12-13,2019-12-19    |  ,2019-12-06,2019-12-13,2019-12-19    4   | class4   |  male  | ,third, third, third    | ,third, third, third        | ,2019-12-20,2019-12-20,2019-12-20     |  ,2019-12-24,2019-12-24,2019-12-24      5   | class5   | female | ,second, second         | ,third, third, third        | ,2019-12-24,2019-12-24,2019-12-24     |  ,2019-12-24,2019-12-24,2019-12-24下面是我用來(lái)獲取詳細(xì)信息的代碼:$datfrm ="00/00/0001";$datto ="31/12/2099";$gender="male";$place_map = ['first' => 1, 'second' => 0.8, 'third' => 0.4];//e1view$query = "SELECT e1 FROM eyfstb WHERE gender = '$gender'";// perform the query ...if ($result = $db->query($query)) {    $finalScore1 = 0;    $scores="";    $last_score="";    /* fetch associative array */    while ($row = $result->fetch_assoc()) {        $efind = $row['e1'];        if (substr_count($efind, ",") >'2'){            $scores = explode(',', $row['e1']);            $last_score = trim($scores[count($scores)-1]);            $finalScore1 += $place_map[$last_score];        }    }}
查看完整描述

5 回答

?
汪汪一只貓

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊

您想要跳過(guò)字段中不正好有 3 個(gè)元素的行e1。在行:之后?$efind = explode(',', $efind);,添加以下內(nèi)容:

if?(count($efind)?!==?3)?{
????continue;
}

在兩個(gè)地方都添加這個(gè)。


代碼中的另一個(gè)問(wèn)題是,當(dāng)您嘗試比較日期時(shí),您將字符串與<=和進(jìn)行比較>=。您應(yīng)該使用strcmp()。

如果不知道表的全部?jī)?nèi)容,就很難看出未定義索引錯(cuò)誤來(lái)自何處。


查看完整回答
反對(duì) 回復(fù) 2023-07-15
?
梵蒂岡之花

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊

首先,更改您的日期


$datfrm ="00/00/0001";

$datto ="31/12/2099";


$datfrm ="00-00-0001";

$datto ="31-12-2099";

然后加


    if (empty($last_score)) {

      $last_score=0;

    }else{


    }

    

之間


$last_score = trim($scores[count($scores)-1]);


$finalScore15 += $place_map[$last_score];

那應(yīng)該可以完全解決你的問(wèn)題。


查看完整回答
反對(duì) 回復(fù) 2023-07-15
?
慕桂英3389331

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊

你正在做


if ($result = $db->query($query)) {

    $finalScore1 = 0;

   ......

}


if ($result = $db->query($query)) {

   $finalScore2 = 0;

   .......

}



echo ($finalscore +$finalscore2);

試著做:


$finalScore1 = 0;

if ($result = $db->query($query)) {

   ......

}


$finalScore2 = 0;

if ($result = $db->query($query)) {

   .......

}



echo ($finalscore +$finalscore2);

你還沒(méi)有定義,在所有上面定義:


$place_map = ['first' => 1, 'second' => 0.8, 'third' => 0.4];

希望這些可以解決您的錯(cuò)誤,根據(jù)數(shù)據(jù)和代碼休息結(jié)果


查看完整回答
反對(duì) 回復(fù) 2023-07-15
?
DIEA

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊

我希望這個(gè)能幫上忙


    <?php 

  


$Date1 = '01-10-2010'; 

$Date2 = '07-12-2010'; 

  


$array = array(); 

$range = 0;


$Variable1 = strtotime($Date1); 

$Variable2 = strtotime($Date2); 

  


for ($currentDate = $Variable1; $currentDate <= $Variable2;  

                                $currentDate += (86400)) { 

                                      

$Store = date('Y-m-d', $currentDate); 

$array[] = $Store;

$range++;


for ($i=0; $i < $range; $i++) { 

    echo $array[$i];

}

  



?> 


查看完整回答
反對(duì) 回復(fù) 2023-07-15
?
MYYA

TA貢獻(xiàn)1868條經(jīng)驗(yàn) 獲得超4個(gè)贊

我在理解你想要從 e1 和 e2 中得到什么時(shí)遇到了一些困難 - 假設(shè)它只是該字段中的最后一個(gè)值。如果我錯(cuò)了,你可以在函數(shù) $eview 中更正它。


下面的代碼使用您發(fā)布的數(shù)據(jù)產(chǎn)生 4.2 的結(jié)果。


$datfrm = "";       // or something like '2010-01-01'

$datto = '2200';    // or something like '2015-12-01'


$gender="male";


$place_map = ['first' => 1, 'second' => 0.8, 'third' => 0.4];


// My understanding of the code is to get the weighted value of the

// last word in the column - if that's wrong, you can change this

// I am assuming you want the date that corresponded to the item you used

// for the final score, so if wrong, you need to change this.

// Also assume there will be the same number of dates as 'e's

//

// return false if bad value, or 0 if not in date range

$eview = function ($row, $ecol, $dcol) use ($place_map, $datfrm, $datto) {

    $parts = array_filter(array_map('trim', explode(",", $row[$ecol])));

    $dates = array_filter(array_map('trim', explode(",", $row[$dcol])));

    if (!$parts || count($parts) != count($dates)) {

        echo "Expected same number of parts and dates!\n";

        return false;

    }

    $date = array_pop($dates);      // Getting last date...

    return ($date >= $datfrm && $date < $datto) ?

           ($place_map[array_pop($parts)] ?? false) : 0;

    };


$finalScore1 = $finalScore2 = 0;


// perform the query ...

$query = "SELECT e1, e2, d1, d2 FROM eyfstb WHERE gender = '{$gender}'";

if ($result = $db->query($query)) {

        /* fetch associative array */

    while ($row = $result->fetch_assoc()) {

      $finalScore1 += $eview($row, 'e1', 'd1') ?: 0;

      $finalScore2 += $eview($row, 'e2', 'd2') ?: 0;

    }

}


echo ($finalScore1+$finalScore2) . "\n";


查看完整回答
反對(duì) 回復(fù) 2023-07-15
  • 5 回答
  • 0 關(guān)注
  • 205 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)