php pdo代码搜索列数组

时间:2015-02-25 07:32:56

标签: php mysql pdo

数据库列中的数据如下所示。

animationno = 300,301

animationdate = 300 - 23-03-2015,301-23-04-2015

当用户搜索300时,它会从animationdate显示输出300-23-03-2015

当用户搜索301时,它会从animationdate显示输出301-23-04-2015

我不知道这可能......或者......如果是的话...我真的没有猜到如何实现这一点...感谢任何帮助......找到解决方案

plz帮助为此..阵列搜索获得解决方案

<?php
$database= new PDO( "connection string goes here" );
$q = $_GET['q'];

$query=$database->prepare("SELECT animationdate FROM animationmaster WHERE animationno = :animationno");
$query->bindParam(':animationno', $q);
$query->execute();

$result = $query -> fetch();
echo json_encode($result);
?>

2 个答案:

答案 0 :(得分:0)

试试这样:

SELECT animationdate FROM animationmaster 
WHERE animationno like '300%'

    $database= new PDO( "connection string goes here" );
    $q = $_GET['q'];
    $param = "'".$q."%'";

    $query=$database->prepare("SELECT animationdate FROM animationmaster WHERE animationno = :animationno");
    $query->bindParam(':animationno', $param);

$query->execute();

答案 1 :(得分:0)

尝试

$query= $database->prepare("
            SELECT animationdate
            FROM animationmaster
            WHERE animationno IN (:animationno)
        ");