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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵