dounai7148 2011-07-06 09:36
浏览 35
已采纳

PHP / Mysql使用现有数组中的值创建一个新数组,求助?

I currently have the following array,

Array (1)
0 => Array (5)
  productid => 1
  qty => 1
  materialid => 12

and I have the following two queries which are

select name as productname, price from products where productid=1

and

select name from materials where materialid=12

I need to link these queries such that the array output is like this or similar:

Array (1)
0 => Array (5)
  productid => 1
  qty => 1
  materialid => 12
  productname => Toothbrush
  price => £3.00

This is basically to output the content on to a basket page. Note that the queries can not be joined as there isn't any joins on the two tables.

Thanks

  • 写回答

4条回答 默认 最新

  • dongshengyin0147 2011-07-06 09:48
    关注

    You could also query both tables at the same time:

    select p.name as productname, m.name as materialname, p.price
        from products p, materials m
        where p.productid=1 and materialid=12
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?