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

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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法