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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

foreach 循環(huán)循環(huán)遍歷要顯示在單獨表中的日期數(shù)組

foreach 循環(huán)循環(huán)遍歷要顯示在單獨表中的日期數(shù)組

PHP
開心每一天1111 2023-09-15 21:13:16
我正在嘗試構(gòu)建我的 foreach 循環(huán)來循環(huán)遍歷時間戳數(shù)組中的所有日期,以便我可以在每個日期的 5 個單獨的表中顯示結(jié)果這是我從數(shù)據(jù)庫獲取信息的功能$users_site = "London";$timeStampFrom = ( [0] => 1596655740 [1] => 1596745740 [2] => 1596828540 [3] => 1597087740 [4] => 1597177800 );$timeStampTo = ( [0] => 1596659340 [1] => 1596749340 [2] => 1596832140 [3] => 1597095000 [4] => 1597181400 );function show_available_equipment($users_site, $timeStampFrom, $timeStampTo){// defines db from instialize page as a global variableforeach ($timeStampFrom as $timeStampStart=>$timeStampTo) {global $db;//SQL statement to query the database for available gear$sql= "SELECT av_inventory.ID AS equipID, av_equipment_type.equipment, "        . "av_inventory.product, av_inventory.serial, av_inventory.current_location, "        . "av_inventory.site, av_inventory.status, av_products.product, av_buildings.building FROM av_inventory JOIN "        . "av_equipment_type ON av_inventory.equipment =av_equipment_type.ID "        . "JOIN av_products ON av_inventory.product = av_products.ID JOIN "        . "av_buildings ON av_inventory.current_location = av_buildings.ID WHERE "        . "av_inventory.site =?  AND av_inventory.ID NOT IN (SELECT av_bookings.av_inventory_id FROM "        . "av_bookings WHERE date_time_from <= ? and date_time_to >= ?)  GROUP BY av_inventory.ID;";        // prepares our sql statement        $stmt = mysqli_stmt_init($db);        //if there is a SQL error exit        if (!mysqli_stmt_prepare($stmt, $sql)) {        header("Location: book_gear.php?error=sqlerror123");         exit();         }}}}這里我嘗試根據(jù)給定的 5 個日期顯示信息。每天一張桌子。目前我剛剛獲得第一天的信息,這讓我認(rèn)為我的函數(shù)循環(huán)不正確。
查看完整描述

1 回答

?
UYOU

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

在獲取SQL數(shù)據(jù)的函數(shù)中,第一次循環(huán)后返回結(jié)果:


function show_available_equipment($users_site, $timeStampFrom, $timeStampTo){

      // defines db from instialize page as a global variable

      foreach ($timeStampFrom as $timeStampStart=>$timeStampTo) { // <----- Only runs once


            ........................


            //if there is a SQL error exit

            if (!mysqli_stmt_prepare($stmt, $sql)) {

                header("Location: book_gear.php?error=sqlerror123");

                exit();

             }

            // otherwise go ahead

            else {

                

                ...........................


                $result = mysqli_stmt_get_result($stmt);

                return $result; //  <---------- Returns after first loop

            }

      }

}

從數(shù)據(jù)庫檢索每個結(jié)果后,您需要將其添加到某種$all_results變量中。循環(huán)完成后,返回$all_results。


查看完整回答
反對 回復(fù) 2023-09-15
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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