警告:implode():在mysql中传递的参数无效

时间:2016-08-22 05:43:12

标签: php mysql sql

<?php        
    include_once("config.php");
    $result=mysqli_query($mysqli,"SELECT * FROM image,tags WHERE image_id=fk_image_id  ORDER BY creation_dt DESC LIMIT 5 ");
    while($res = mysqli_fetch_array($result)) {
        $tagname=$res['tag_txt'];
        $cols = implode(',','array_keys($tagname)');
        echo $cols;
        echo "<tr>"."<img  src='http://localhost:8080/memes/".$res['path_txt']."' width='380' height='280' style='padding: 10px;'  />"."</tr>";            
    }        
?> 

这是我传递参数的code.error,这个内爆函数是否正确? 我正在使用插入查询进行爆炸功能

2 个答案:

答案 0 :(得分:0)

implode — Join array elements with a string

array_keys — Return all the keys or a subset of the keys of an array

Example :

$array = array("1" => "PHP code tester",  
              "foo" => "bar",
               5 => 89009, 
              "case" => "Random Stuff",
              "PHP Version" => phpversion()
              );

$arrayKey = implode(',',array_keys($array));

echo $arrayKey;

output will be : 1,foo,5,case,PHP Version

But you give a string parameter in this line

$cols = implode(',','array_keys($tagname)');

So you get warning : implode(): Invalid arguments passed in

actually this line will be :

$cols = implode(',',array_keys($tagname));

答案 1 :(得分:-2)

尝试更新代码

    include_once("config.php");
    $result=mysqli_query($mysqli,"SELECT path_txt,GROUP_CONCAT(tag_txt SEPARATOR ', ') as image_tag FROM image,tags WHERE image_id=fk_image_id GROUP BY path_txt ORDER BY creation_dt DESC LIMIT 5");

    while($res = mysqli_fetch_array($result)) 
    {
        $tagname = $res['image_tag'];
        echo $tagname;
        echo "<tr>"."<img  src='http://localhost:8080/memes/".$res['path_txt']."' width='380' height='280' style='padding: 10px;'  />"."</tr>";
    }//end of while loop
相关问题