如何使用php和mysql基于循环计数器在循环中运行多选语句 [英] how do run multi select statement in loop based on loop counter with php and mysql

查看:72
本文介绍了如何使用php和mysql基于循环计数器在循环中运行多选语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP和MySQL



我有两张桌子:



产品(product_id,product_name)



价格(product_id,price_id,价格,日期)< br $>


任何产品都有无限价格



价格表中日期字段的类型是datetime (如 2014-02-23 18:41:22 ) - 当我保存此字段中保存的任何记录当前日期时间时(可以使用此字段确定最后一条记录)。



我想为所有产品提供一个循环,可以对任何产品采取以下行动:



 1)从与当前产品相关的价格表中获取最后日期并将其设置为$ last_Date 





例如if当前product_id是1获取价格表中最后一条记录的日期,product_id = 1且date = $ last_Date

 2)获取与当前产品相关的价格表的最后价格





例如,如果当前产品id为1,则获取price_id = 1和date = $ last_Date的价格表中最后一条记录的价格



 3)从最近2条记录中获得不同的字段价格





例如,如果当前产品ID为1,则获得不同价格表中最后一条记录2的现场价格之间,product_id = 1,日期= $ last_Date



 4)得到最小值和最大值* price *字段值product_id = 1和date = $ last_Date 

解决方案

last_Date





例如,如果当前product_id为1,则获取price_id = 1且date =


last_Date
的价格表中最后一条记录的日期

 2)从与当前产品相关的价格表中获取最后价格





例如如果当前产品id为1,则获取price_id = 1且date =

last_Date



 3)在最近2条记录的场地价格之间取得差异





例如,如果当前产品ID为1,则在product_id = 1和date =

的价格表中的最后一条记录2记录的字段价格之间有所不同

i work with PHP And MySQL

I have two table :

Products (product_id,product_name)

Prices (product_id,price_id,price,date)

Any product have unlimited price

Type of "date" field in table "Prices" is datetime (like 2014-02-23 18:41:22) – when I saving any record current datetime saved in this field (last record can be determine with this field) .

I want a loop for all products that can do below actions for any product :

1)get Last date from prices table that related with current product and set it to $last_Date



for example if current product_id is 1 get date of last record in price table that product_id=1 and date=$last_Date

2)get Last price from prices table that related with current product



for example if current product id is 1 get price of last record in price table that product_id=1 and date=$last_Date

3)get different between field price from last 2 record



for example if current product id is 1 get different between field price of last record 2 record in price table that product_id=1 and date=$last_Date

4)get min and max *price* field value that product_id=1 and date=$last_Date

解决方案

last_Date



for example if current product_id is 1 get date of last record in price table that product_id=1 and date=


last_Date

2)get Last price from prices table that related with current product



for example if current product id is 1 get price of last record in price table that product_id=1 and date=


last_Date

3)get different between field price from last 2 record



for example if current product id is 1 get different between field price of last record 2 record in price table that product_id=1 and date=


这篇关于如何使用php和mysql基于循环计数器在循环中运行多选语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆