2013-12-11 33 views
-2

我正在开发移动购物车,我正在学习本教程,http://go.developer.ebay.com/devzone/articles/building-html5-powered-shopping-cart-ios-part-1设计Html5 Powered购物车?

在本教程中,Iam将产品作为Json获取到Html中。对于使用下面的代码,把产品为JSON(IAM),

<?php 

// simulates result of db query for categories 
$categories = array(); 
$categories[] = array(id => 1, parent_id => 0, name => 'root'); 
$categories[] = array(id => 2, parent_id => 1, name => 'Compact Discs'); 
$categories[] = array(id => 3, parent_id => 1, name => 'Concert Souvenirs'); 

// simulates result of db query for products 
$products = array(); 
$products[] = array(id => 1, category_id => 2, sku => 'CD001', price=>15.00, name => 'CD: Greatest Hits'); 
$products[] = array(id => 2, category_id => 2, sku => 'CD002', price=>15.00, name => 'CD: Unplugged'); 
$products[] = array(id => 3, category_id => 2, sku => 'CD003', price=>15.00, name => 'CD: World Tour'); 
$products[] = array(id => 4, category_id => 3, sku => 'PD001', price=>10.00, name => 'Souvenir Pin'); 
$products[] = array(id => 5, category_id => 3, sku => 'PD002', price=>10.00, name => 'Mug'); 
$products[] = array(id => 6, category_id => 3, sku => 'PD003', price=>20.00, name => 'Hat'); 
$products[] = array(id => 7, category_id => 3, sku => 'PD004', price=>12.00, name => 'Summer Tour Poster'); 
$products[] = array(id => 8, category_id => 3, sku => 'PD005', price=>5.00, name => 'Concert Program'); 
?> 

如果我跑catalog.php,我得到JSON输出但有错误,像所有的行未定义的常量。根据上述教程的指导,我创建了任何表格。但是当我访问索引文件时,我只是空白屏幕。

请帮助我获得输出。

+0

如果您收到实际的错误消息,那将会很有帮助。 – andrewsi

回答

1

您必须在php中引用字符串数组键,否则您将收到有关未定义常量的警告。

$categories[] = array('id' => 2, 'parent_id' => 1, 'name' => 'Compact Discs');