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

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

從 GET 請(qǐng)求中解析數(shù)據(jù)庫表

從 GET 請(qǐng)求中解析數(shù)據(jù)庫表

PHP
蕭十郎 2022-12-23 16:27:18
早上好,我最近一直在努力解決這個(gè)問題,因?yàn)槲覍?duì) PHP 和 MySQL 還很陌生。我有一個(gè)帶有“視頻”表的數(shù)據(jù)庫,我在其中存儲(chǔ)了有關(guān)視頻的有用信息,并且我有一個(gè)名為 search.php 的文檔,該文檔將根據(jù) GET 請(qǐng)求顯示特定視頻。請(qǐng)求看起來像這樣:http://example.ex/search.php?tag=EXAMPLE1邏輯是像這樣存儲(chǔ)標(biāo)簽值:if(!empty($_GET["tag"])){     // Get videos from tag only     $curTag = strval($_GET["tag"]);     displayByTag($curTag); //the function that parse the database}我已準(zhǔn)備好連接:$server = "localhost";$username = "root";$password = "";$db = "mydatabase";$conn = mysqli_connect($server, $username, $password, $db);$query = "SELECT * FROM videos";$response = array();$result = mysqli_query($conn, $query);while($row = mysqli_fetch_array($result)) {     $response[] = $row;}從技術(shù)上講,截至目前,我的表存儲(chǔ)在里面$response[].我需要做的是解析數(shù)據(jù)庫并查找“標(biāo)簽”列,拆分其字符串值(表中的“EXAMPLE1,EXAMPLE2,EXAMPLE3”),然后查看是否GET 值匹配其中之一。那是我需要你幫助的時(shí)候。我了解邏輯和步驟,但無法將其“翻譯”成 PHP。這是我會(huì)做的(人類語言):function displayByTag($tag) {     for each $video-item inside $array {          $tagsArray = explodes(",", $video-item[tags-column]); //That's how I split the tags stored inside the table          for i as integer = 0 to $tagsArray.length {               if $tagsArray(i) == $tag {                    //THATS A MATCH               }          }     }}這是正確的方法嗎?我怎樣才能將這種“人類”語言翻譯成 PHP 代碼?謝謝您的幫助。
查看完整描述

1 回答

?
慕工程0101907

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

經(jīng)過一些測(cè)試和調(diào)試后,我的功能很容易運(yùn)行。如果有人感興趣:


function searchVideos($search) {

    $currentSearchQueries = explode(" ", strtoupper($search)); //Split the searched tags in a array and make them to uppercase for easier comparaison.


    //Establish a connection the MySql Database

    $server = "localhost";

    $username = "root";

    $password = "";

    $db = "mydatabase";

    $conn = mysqli_connect($server, $username, $password, $db);


    //Select all the entries from my 'videos' table

    $query = "SELECT * FROM videos";

    $response = array();

    $result = mysqli_query($conn, $query);

    while($row = mysqli_fetch_array($result)){

        $response[] = $row; //Place them into a array

    }


    //Parse the array for matching entries

    foreach ($response as &$video){ //Each entries goes through the process

        foreach ($currentSearchQueries as $t) {

            //We compare if one the tags searched matches for this particular entry

            if((strtoupper($video[tags]) == $t) {

                //THAT'S A MATCH

            }

        }

    }

}

編碼很有趣,期待新的體驗(yàn)!


查看完整回答
反對(duì) 回復(fù) 2022-12-23
  • 1 回答
  • 0 關(guān)注
  • 77 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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