I have problem in this code, I'm taking information from two tables and "where news_id=$dz" is not working. Here is the page which include this code.
Here is my code:
<?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");
- here you should use $id
next problem: - DO NOT USE for($i=0;$i<CountImages($id);$i++)
change it to
$len = CountImages($id);
for($i=0;$i<$len;$i++)
because you do not need to perform SQL query for each FOR iteration, or even remove it - as you have $images array, iterate over it
next problem:
$d=mysql_query("select * from `images` where news_id=$id");
return mysql_num_rows($d);
DO NOT USE mysql_num_rows
, use SQL count(*)
- because it will send only 1 number from mysql to php, instead of whole result set
In the 1st query, change && mxare='kaxeti'
by AND mxare='kaxeti'
. Also, in functions FetchImage
and CountImages
, change news_id=$dz
by news_id=$id
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.