dpgbh20688 2015-08-31 15:02
浏览 47

在查询中使用in_array

Problem:

Formats and topics produces arrays derived from an AJAX post

Proposed Solution:

Break the array into individual strings and compare each string with its respective query item using php internal function in_array

However, I am not sure how to implement it.

Below is the code:

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

I am using in_array because Implode did not work:

  $formats = implode('","', $formatsArray);
   $topics = implode('","', $topicsArray);

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

stage is just a string not an array.

I would like to use in-array within the query,

How the array is created (in javscript):

optionScope = $(this);
// Stage 4 option A
var formats = [];
optionScope.data().formats = formats;

stage4_optiona.on('click', function(){

  continue4.css('opacity', '1');
    continue4.on('click', function(){
    optionScope.data().formats.push("Online classroom");

        stage5.show();
        stage4.hide();
    });
});

then post

  <script type='text/javascript'>
        /* attach a submit handler to the form */
$(function(){
  optionScope = $(this);                    // wait until dom is ready

$("#formMail").submit(function(event) {
  /* stop form from submitting normally */
  event.preventDefault();      /* stop form from submitting normally */

          $.ajax({
              url: "functions/contact.php",
              type: "post",
              data: {stage : optionScope.data().stage,
                    topics: optionScope.data().topic,
                    formats: optionScope.data().formats,
                    fname: $('#fname').val(),
                    email: $('#email').val(),
                    humancheck: $('#humancheck').val()
                  },
              success: function (response) {
                  console.log("data sent successfully");

                  window.location = response;


              },
              error: function (xhr, desc, err) {
                  console.log(xhr);
                  console.log("Details: " + desc + "
Error:" + err);
              }
          });
                  });
  });
</script>

Update:

Array( 
  [0] => Videos 
  [1] => Blogs/articles 
  [2] => books
)

Array(
 [0] => idea generation 
 [1] => mindset 
 [2] => psychology
) 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗
    • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路