【问题标题】:I am using wordpress prepare, cannot use IN( array), mysql php我正在使用 wordpress 准备,不能使用 IN(array),mysql php
【发布时间】:2016-08-03 05:13:22
【问题描述】:

看看我的代码,因为我使用 wordpress 准备,所以内爆数组对我不起作用。我找出问题所在。我不能在查询中放入一个 $args。比方说,如果我有 3 个 %s,我需要像 $args,$args,$args 这样的输入。因此,我想请问您有什么办法可以解决这个问题?请不要删除 $wpdb->prepare,因为它是出于安全目的,如果我错了,请纠正我。因为我必须使用 %s,所以有一个问题。

<?php
$arg = array('a','b','c');
$que= implode(',', array_fill(0, $arg, '%s'));

$args = implode(',', $arg);

$sym = $wpdb->get_results( $wpdb->prepare("
	SELECT DISTINCT disease FROM dis WHERE disease IN ($que)
	",$args));//the problem is that if there are three %s, I need to put $args,$args,$args
print_r($sym);//echo nothing
?>

【问题讨论】:

  • 有错误输出吗?
  • 没有错误输出,它只是没有回显。
  • WHERE FIND_IN_SET(疾病,$que)

标签: php mysql wordpress


【解决方案1】:

试试这个

$arg = array('a','b','c');
$que= implode(',', array_fill(0, 3, '%s') );

$sym = $wpdb->get_results( $wpdb->prepare("
    SELECT DISTINCT disease FROM dis WHERE disease IN ($que)
    ",$arg));

print_r($sym);

请看: http://php.net/manual/en/function.array-fill.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多