pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  1. <i id='80flS'><tr id='80flS'><dt id='80flS'><q id='80flS'><span id='80flS'><b id='80flS'><form id='80flS'><ins id='80flS'></ins><ul id='80flS'></ul><sub id='80flS'></sub></form><legend id='80flS'></legend><bdo id='80flS'><pre id='80flS'><center id='80flS'></center></pre></bdo></b><th id='80flS'></th></span></q></dt></tr></i><div class="ka2acim" id='80flS'><tfoot id='80flS'></tfoot><dl id='80flS'><fieldset id='80flS'></fieldset></dl></div>
    <tfoot id='80flS'></tfoot>

      <legend id='80flS'><style id='80flS'><dir id='80flS'><q id='80flS'></q></dir></style></legend>
      • <bdo id='80flS'></bdo><ul id='80flS'></ul>

      <small id='80flS'></small><noframes id='80flS'>

    1. 將數組轉換為單獨的字符串

      convert an array into individual strings(將數組轉換為單獨的字符串)
    2. <i id='v6usa'><tr id='v6usa'><dt id='v6usa'><q id='v6usa'><span id='v6usa'><b id='v6usa'><form id='v6usa'><ins id='v6usa'></ins><ul id='v6usa'></ul><sub id='v6usa'></sub></form><legend id='v6usa'></legend><bdo id='v6usa'><pre id='v6usa'><center id='v6usa'></center></pre></bdo></b><th id='v6usa'></th></span></q></dt></tr></i><div class="ig2c0wm" id='v6usa'><tfoot id='v6usa'></tfoot><dl id='v6usa'><fieldset id='v6usa'></fieldset></dl></div>
        <tbody id='v6usa'></tbody>

        <legend id='v6usa'><style id='v6usa'><dir id='v6usa'><q id='v6usa'></q></dir></style></legend>
      • <tfoot id='v6usa'></tfoot>

            <small id='v6usa'></small><noframes id='v6usa'>

              <bdo id='v6usa'></bdo><ul id='v6usa'></ul>

                本文介紹了將數組轉換為單獨的字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有以下數組,我想將它們中的每一個都轉換為單獨的字符串.換句話說,將數組分解為單獨的部分.

                I have the following arrays and I would like to convert each one of them into individual strings. In other words, break the array into individual pieces.

                  $formatsArray = $_POST['formats'];
                      $topicsArray = $_POST['topics'];
                

                這是因為我想在以下查詢中包含單個字符串

                This is because I would like to include the individual strings in the following query "

                  $resources = "select * from resources where
                                    stage LIKE '%".$stage."%'
                                    AND format LIKE '%".$formats."%'";
                
                
                      $run_query = mysqli_query($con, $resources);
                

                這是因為 format 需要一個單獨的字符串進行比較,例如假設數組是 ["video", "blogs", "articles"],如果 format 是與 video,blogs,articles 相比,而不是視頻,博客或文章.

                This is because format expect an individual string for comparison, such as lets assume the array is ["video", "blogs", "articles"], it wouldn't work if format was to be compared with video,blogs,articles but rather video, blogs or articles.

                我希望這很清楚,如有任何澄清,請提供建議.

                I hope this is clear, and for any clarification, please advise.

                一切順利,

                更新:

                $formats = explode(',', $formatsArray);
                      $topics = explode(',', $topicsArray);
                
                
                      $resources = "select * from resources where
                                    stage LIKE '%".$stage."%'
                                    AND format LIKE '%".$formats."%' AND topic LIKE '%".$topics."%' ";
                

                更新:

                $run_query = mysqli_query($con, $resources);
                
                
                  while($row = mysqli_fetch_array($run_query)) {
                
                    $data[] = array(
                      'format' => $row['format'],
                      'title' => $row['title'],
                      'costs' => $row['cost'],
                      'stage' => $row['stage'],
                      'topic' => $row['topic'],
                      'link' => $row['link']
                    );
                  }
                

                更新

                  include('db.php');
                
                
                  $query = 'select * from resources where ';
                  $query .= 'stage LIKE :stage and';
                  $execute[':stage'] = '%' . $stage . '%';
                  if(!empty($_POST['formats'])){
                  foreach($_POST['formats'] as $key => $format) {
                      $query .= 'format LIKE :format' . $key . ' and ';
                      $execute[':format' . $key] = '%' . trim($format) . '%';
                  }
                  }
                  if(!empty($_POST['topics'])){
                  foreach($_POST['topics'] as $key => $topic) {
                      $query .= 'topic LIKE :topic' . $key . ' and ';
                      $execute[':topic' . $key] = '%' . trim($topic)  . '%';
                  }
                  }
                  $query = rtrim($query, ' and ');
                  if(!empty($execute)) {
                      $stmt = $con->prepare($query);
                      $stmt->execute($execute);
                  } else {
                      echo 'You must search for something';
                  }
                
                
                      while($row = mysqli_fetch_array($query)) {
                
                        $data[] = array(
                          'format' => $row['format'],
                          'title' => $row['title'],
                          'costs' => $row['cost'],
                          'stage' => $row['stage'],
                          'topic' => $row['topic'],
                          'link' => $row['link']
                        );
                      }
                

                推薦答案

                我認為這樣做可以.這也將通過使用準備好的語句來解決注入漏洞.

                I think this would do it. This also will resolve the injection hole by using prepared statements.

                $query = 'select * from resources where ';
                if(!empty($_POST['formats'])){ 
                foreach($_POST['formats'] as $key => $format) {
                    $query .= 'stage LIKE :stage' . $key . ' or ';
                    $execute[':stage' . $key] = '%' . trim($format) . '%';
                }
                }
                if(!empty($_POST['topics'])){
                foreach($_POST['topics'] as $key => $topic) {
                    $query .= 'topic LIKE :topic' . $key . ' or ';
                    $execute[':topic' . $key] = '%' . trim($topic)  . '%';
                }
                }
                $query = rtrim($query, ' or ');
                if(!empty($execute)) {
                    echo $query;
                    print_r($execute);
                    //$stmt = $mysqli->prepare($query);
                    //$stmt->execute($execute);
                } else {
                    echo 'You must search for something';
                }
                

                給你一個查詢

                select * from resources where stage LIKE :stage0 or stage LIKE :stage1 or topic LIKE :topic0 or topic LIKE :topic1 or topic LIKE :topic2 or topic LIKE :topic3

                select * from resources where stage LIKE :stage0 or stage LIKE :stage1 or topic LIKE :topic0 or topic LIKE :topic1 or topic LIKE :topic2 or topic LIKE :topic3

                和綁定值:

                Array
                (
                    [:stage0] => %test%
                    [:stage1] => %test1%
                    [:topic0] => %value1%
                    [:topic1] => %value2%
                    [:topic2] => %value3%
                    [:topic3] => %value4%
                )
                

                這是我認為數據已配對時的初始代碼..

                Here's the initial code I had for when I thought the data was paired..

                foreach($formats as $key => $format) {
                    $topic = $topics[$key];
                    $query .= '(stage LIKE :stage' . $key . ' and topic LIKE :topic' . $key . ') or ';
                    $execute[':stage' . $key] = '%' . trim($format) . '%';
                    $execute[':topic' . $key] = '%' . trim($topic)  . '%';
                }
                

                關于準備好的語句的一些鏈接:
                http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
                http://php.net/manual/en/mysqli.prepare.php
                http://php.net/manual/en/mysqli-stmt.execute.php

                A few links on prepared statements:
                http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
                http://php.net/manual/en/mysqli.prepare.php
                http://php.net/manual/en/mysqli-stmt.execute.php

                這篇關于將數組轉換為單獨的字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                <small id='BoI1C'></small><noframes id='BoI1C'>

              1. <i id='BoI1C'><tr id='BoI1C'><dt id='BoI1C'><q id='BoI1C'><span id='BoI1C'><b id='BoI1C'><form id='BoI1C'><ins id='BoI1C'></ins><ul id='BoI1C'></ul><sub id='BoI1C'></sub></form><legend id='BoI1C'></legend><bdo id='BoI1C'><pre id='BoI1C'><center id='BoI1C'></center></pre></bdo></b><th id='BoI1C'></th></span></q></dt></tr></i><div class="qweke2m" id='BoI1C'><tfoot id='BoI1C'></tfoot><dl id='BoI1C'><fieldset id='BoI1C'></fieldset></dl></div>

                1. <tfoot id='BoI1C'></tfoot>
                          <tbody id='BoI1C'></tbody>
                        <legend id='BoI1C'><style id='BoI1C'><dir id='BoI1C'><q id='BoI1C'></q></dir></style></legend>

                          <bdo id='BoI1C'></bdo><ul id='BoI1C'></ul>
                          主站蜘蛛池模板: 食安观察网| 电动垃圾车,垃圾清运车-江苏速利达机车有限公司 | 镀锌方管,无缝方管,伸缩套管,方矩管_山东重鑫致胜金属制品有限公司 | 作文导航网_作文之家_满分作文_优秀作文_作文大全_作文素材_最新作文分享发布平台 | 范秘书_懂你的范文小秘书 | 纸塑分离机-纸塑分离清洗机设备-压力筛-碎浆机厂家金双联环保 | 非甲烷总烃分析仪|环控百科| 机构创新组合设计实验台_液压实验台_气动实训台-戴育教仪厂 | Copeland/谷轮压缩机,谷轮半封闭压缩机,谷轮涡旋压缩机,型号规格,技术参数,尺寸图片,价格经销商 CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 冰晶石|碱性嫩黄闪蒸干燥机-有机垃圾烘干设备-草酸钙盘式干燥机-常州市宝康干燥 | 震动筛选机|震动分筛机|筛粉机|振筛机|振荡筛-振动筛分设备专业生产厂家高服机械 | 厦门ISO认证|厦门ISO9001认证|厦门ISO14001认证|厦门ISO45001认证-艾索咨询专注ISO认证行业 | 海峰资讯 - 专注装饰公司营销型网站建设和网络营销培训 | 都江堰招聘网-都江堰人才网 都江堰人事人才网 都江堰人才招聘网 邢台人才网_邢台招聘网_邢台123招聘【智达人才网】 | 高低温万能试验机-复合材料万能试验机-馥勒仪器 | 塑料异型材_PVC异型材_封边条生产厂家_PC灯罩_防撞扶手_医院扶手价格_东莞市怡美塑胶制品有限公司 | 成都中天自动化控制技术有限公司 | 博莱特空压机|博莱特-阿特拉斯独资空压机品牌核心代理商 | 大行程影像测量仪-探针型影像测量仪-增强型影像测量仪|首丰百科 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 短信营销平台_短信群发平台_106短信发送平台-河南路尚 | 浇钢砖,流钢砖_厂家价低-淄博恒森耐火材料有限公司 | 厂厂乐-汇聚海量采购信息的B2B微营销平台-厂厂乐官网 | 板框压滤机-隔膜压滤机-厢式压滤机生产厂家-禹州市君工机械设备有限公司 | 二手Sciex液质联用仪-岛津气质联用仪-二手安捷伦气质联用仪-上海隐智科学仪器有限公司 | 博客-悦享汽车品质生活 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 科威信洗净科技,碳氢清洗机,超声波清洗机,真空碳氢清洗机 | 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰 | 基业箱_环网柜_配电柜厂家_开关柜厂家_开关断路器-东莞基业电气设备有限公司 | 北京发电机出租_发电机租赁_北京发电机维修 - 河北腾伦发电机出租 | 上海办公室设计_办公楼,写字楼装修_办公室装修公司-匠御设计 | 排烟防火阀-消防排烟风机-正压送风口-厂家-价格-哪家好-德州鑫港旺通风设备有限公司 | 河南中整光饰机械有限公司-抛光机,去毛刺抛光机,精密镜面抛光机,全自动抛光机械设备 | 防水套管-柔性防水套管-刚性防水套管-上海执品管件有限公司 | 闭端端子|弹簧螺式接线头|防水接线头|插线式接线头|端子台|电源线扣+护线套|印刷电路板型端子台|金笔电子代理商-上海拓胜电气有限公司 | 一路商机网-品牌招商加盟优选平台-加盟店排行榜平台 | 烟气换热器_GGH烟气换热器_空气预热器_高温气气换热器-青岛康景辉 | 北京三友信电子科技有限公司-ETC高速自动栏杆机|ETC机柜|激光车辆轮廓测量仪|嵌入式车道控制器 | 智慧旅游_智慧景区_微景通-智慧旅游景区解决方案提供商 | 酒精检测棒,数显温湿度计,酒安酒精测试仪,酒精检测仪,呼气式酒精检测仪-郑州欧诺仪器有限公司 | 防爆型气象站_农业气象站_校园气象站_农业四情监测系统「山东万象环境科技有限公司」 |