Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL何处查询不起作用_Php_Mysql - Fatal编程技术网

Php MySQL何处查询不起作用

Php MySQL何处查询不起作用,php,mysql,Php,Mysql,我在这段代码中遇到了问题,我从两个表中获取信息,“where news_id=$dz”不起作用。其中包括此代码 这是我的密码: <?php mysql_query("SET NAMES UTF8"); $result = mysql_query("SELECT dz,title FROM dzeglebi where raioni='ყვარლის მუნიციპალიტეტი' && mxare='kaxeti' ORDER BY title ASC", $db); $m

我在这段代码中遇到了问题,我从两个表中获取信息,“where news_id=$dz”不起作用。其中包括此代码

这是我的密码:

<?php
mysql_query("SET NAMES UTF8");
$result = mysql_query("SELECT dz,title FROM dzeglebi where raioni='ყვარლის მუნიციპალიტეტი' && mxare='kaxeti' ORDER BY title ASC", $db);
$myrow = mysql_fetch_array ($result);

printf(
       "<h2><li>
       <strong><a href='../../dzeglebi.php?id=%s'>%s</a>
       </strong></li></h2>",$myrow["dz"],$myrow["title"]);


function FetchImage($id)
{
    $images=array();
    $x=0;
    $d=mysql_query("select * from `images` where news_id=$dz");
    while($data=mysql_fetch_array($d))
    {
        $images["big"][$x]=$data["image"];
        $images["small"][$x]=$data["small"];
        $x++;
    }   
return $images;
}
function CountImages($id)
{
$d=mysql_query("select * from `images` where news_id=$dz");
return mysql_num_rows($d);  
}
$imgs=FetchImage($id);

 for($i=0;$i<CountImages($id);$i++)
{
echo'

 <img src="../'.$imgs["big"][$i].'" >';
}



?>

在第一次查询中,通过
和mxare='kaxeti'
更改
&&mxare='kaxeti'
。 另外,在函数
FetchImage
CountImages
中,通过
news\u id=$id
更改
news\u id=$id
函数CountImages($id)
{
$d=mysql\u query(“从图片中选择*,其中news\u id=$dz”);
-这里应该使用$id


下一个问题:-不要对($i=0;$i)使用
,预期输出和实际输出是什么?首先应该连接到$db。在函数中不能访问$dz。在php函数内部,只能访问参数和局部变量。因此,应该传递$dz-az函数参数。(或者作为全局变量访问它,但作为参数传递是更好的方法。)可能还有其他问题……您在
FetchImage($id)
CountImages($id)中有
$id
参数
使用where on
where news\u id=$dz
应该有
$id
检查您的$db变量我理解您的意思,但我想知道“news\u id”=$dz我怎么做?
$len = CountImages($id);
for($i=0;$i<$len;$i++)
$d=mysql_query("select * from `images` where news_id=$id");
return mysql_num_rows($d);