繁体   English   中英

MySQL WHERE查询无法运作

[英]MySQL WHERE query not working

我在此代码中有问题,我从两个表中获取信息,并且“ 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].'" >';
}



?>

function CountImages($id) { $d=mysql_query("select * from images where news_id=$dz"); -在这里您应该使用$ id

下一个问题:-请勿for($i=0;$i<CountImages($id);$i++)将其更改为

$len = CountImages($id);
for($i=0;$i<$len;$i++)

因为您不需要为每个FOR迭代执行SQL查询,甚至不需要删除它-因为您有$ images数组,因此可以对其进行迭代

下一个问题:

$d=mysql_query("select * from `images` where news_id=$id");
return mysql_num_rows($d);  

不要使用mysql_num_rows ,请使用SQL count(*) -因为它将仅从mysql发送一个数字到php,而不是整个结果集

在第一个查询中,将&& mxare='kaxeti'更改为AND mxare='kaxeti' 另外,在函数FetchImageCountImages ,将news_id=$dz更改为news_id=$id

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM