美好的一天 我正在编写一个必须使用服务器的php文件并将其显示到HTML表中的网站。 PHP文件生成JSON数组并具有以下输出
Array
(
[0] => Array
(
)
[1] => Array
(
[Description] => Bacon, feta and avo panini
[Order_Number] => 7111
)
[2] => Array
(
[Description] => Bacon, feta and avo panini
[Order_Number] => 7112
)
[3] => Array
(
[Description] => Cheese, ham and pineapple panini
[Order_Number] => 7111
)
[4] => Array
(
[Description] => Cheese, ham and pineapple panini
[Order_Number] => 7112
)
[5] => Array
(
[Description] => Grilled cheese panini
[Order_Number] => 7111
)
我的问题是如何将数据显示到一个html表格中,该表格提供了两列名为描述和订单号的列?
提前致谢
答案 0 :(得分:0)
你去:
class deal():
def __init__(self, deal_container, parent):
'''
Initializes deal object
Precondition: 0 > price
Precondition: 0 > old_price
Precondition: len(currency) = 3
:param deal_container: obj
'''
self.css = self.parent.css
self.deal_container = deal_container
self.parent = parent
self.title = self.extract_string('title')
self.currency = self.parent.currency
self.price = self.extract_price('price')
self.old_price = self.extract_price('old_price')
self.brand = self.extract_string('brand')
self.image = self.extract_image('image')
self.description = self.extract_string('description')
#define amazon category as clearance_url
#define all marketplace deals
def __str__(self):
return self.title
def extract_string(self, element, deal):
'''
:param object deal: deal object to extract title from
:param string element: element to look for in CSS
:return string result: result of string extract from CSS
'''
tag = self.css[element]['tag']
attr = self.css[element]['attr']
name = self.css[element]['name']
result = deal.find(tag, attrs={attr: name})
if result:
if element == 'title':
return result.text
elif element == 'price':
result = self.extract_price(result).text
if result:
return result
elif element == 'image':
result = self.extract_image(result)
return False
你的.php文件里面的想法用普通的方式写你的HTML代码但是这里的方式是php的逻辑我只是在你的json数组中做了一个foreach循环并且回显了row元素和数据< / p>