【问题标题】:fetching images from mysql throw smarty从 mysql 获取图像 throw smarty
【发布时间】:2014-08-26 12:13:44
【问题描述】:

我是 smarty 的新手,我有一个小问题,我无法为我的帖子获取图像。我将图像路径存储在表 ( images ) 中,将帖子存储在表 (posts) 中:

我的php代码是

    $get_new_jobs=$mysqli->query("select id,numview,title,cat1,details,country,active from ads where country='".$country_en."' and active='1' order by id desc limit 4");
    $nums=$get_new_jobs->num_rows;
    while($row=$get_new_jobs->fetch_assoc()){

        $mm[]=$row;

    }

$smarty->assign('posts',$mm);
$smarty->assign('image',$the_images_name);
$smarty->display('posts.tpl');

我的图片代码是

$sql=mysqli->query("select adid,image,p from images where adid='".$row['id']."'");
$fet = $sql->fetch_assoc();
$the_images_name = $fet['image'];

tpl 代码是

<table width="100%" border="0" cellpadding="5">
{foreach from=$posts item=item}
<tr valign="top">
<td>        
{$image}
<br />
{$item.title}
</td>
</tr>        
{/foreach}
</table>

那么我怎样才能为每个帖子获取每张图片。

问候

【问题讨论】:

  • 第一件事 {$image} 应该像 第二你每个帖子有多个图片吗?
  • 我怎样才能在帖子循环中插入图片查询亲爱的......这就是我需要的

标签: php mysqli smarty


【解决方案1】:

基本上,您可以在循环中获取图像,然后可以将图像 url 分配给您发送帖子数据的同一数组的索引

PHP部分

$get_new_jobs=$mysqli->query("select id,numview,title,cat1,details,country,active from ads where country='".$country_en."' and active='1' order by id desc limit 4");
    $nums=$get_new_jobs->num_rows;
    while($row=$get_new_jobs->fetch_assoc())
    {

        $sql=mysqli->query("select adid,image,p from images where adid='".$row['id']."'");
        $fet = $sql->fetch_assoc();
        $the_images_name = $fet['image'];
        $row['image_url']= $the_images_name;
        $mm[]=$row;
     }

$smarty->assign('posts',$mm);
$smarty->display('posts.tpl'); 

tpl部分

<table width="100%" border="0" cellpadding="5">
{foreach from=$posts item=item}
<tr valign="top">
<td>        
<img src="{$item.image_url}">
<br />
{$item.title}
</td>
</tr>        
{/foreach}
</table>

【讨论】:

  • @BbWay 随时为您提供帮助 :)
猜你喜欢
  • 1970-01-01
  • 2012-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-05
  • 2013-03-05
相关资源
最近更新 更多