dsa80833 2015-08-10 11:54
浏览 52
已采纳

从MySQL获取特定数据并使用PHP回显它

I am new here and just registered to ask a question. First of all i am newbie to PHP,so i have not tons of experience in it. My problem is the following:

I got two tables in my database. The first one is called products. The products table gives new products in my shop an unique ID. The second one is the products_to_categories table, in this table the products_id gets an cateogries_id so you know which product belongs to which category.

Now i need to echo the images (products_images in products-table) from the last 4 products (there is also a products_date_added attribute) of a category. All i managed to do until now is to echo the links of the images from the product tables:

mysql_select_db('example2');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_assoc($retval))
{
    echo "Product Image : {$row['products_image']}  <br> ".
         "--------------------------------<br>";
} 
echo "Fetched data successfully
";
mysql_close($conn);

?>    
</body>

could someone help me to do that? thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongzai3917 2015-08-10 12:00
    关注

    Wrap img tags (html) around the links you echo, so

    echo "Product Image : {$row['products_image']}  <br> ".
    

    becomes

    echo "Product Image : <img src=\"{$row['products_image']}\"/>  <br> ".
    

    and as for the results, you can limit the search by using LIMIT 4 and ORDER BY to sort it by the date products_date_added

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置