RSS

Create api categories and sub categories

24 Nov

<?php
//http://www.brenelz.com/blog/how-to-create-a-simple-api-with-php-and-mysql/
//isc_shopping_comparison_categories
//Create Database connection
header(‘Content-Type: application/json’);
include’conn.php’;

$sql = mysql_query(“select * from isc_categories where catparentid=0”);
// parent categories node
$categories = array(“Categories” => array());

//print_r($categories);

while ($row = mysql_fetch_array($sql,MYSQL_ASSOC)) {
$cat_id = $row[‘categoryid’];
//print_r($row);
$ssql = mysql_query(“select * from isc_categories where catparentid=’$cat_id'”);

// single category node
$category = array(); // temp array
$category[“categoryid”] = $row[“categoryid”];
$category[“name”] = $row[“catname”];
$category[“sub_categories”] = array(); // subcategories again an array

while ($srow=mysql_fetch_array($ssql,MYSQL_ASSOC)) {
$subcat = array(); // temp array
$subcat[“categoryid”] = $srow[‘categoryid’];
$subcat[“name”] = $srow[‘catname’];
// pushing sub category into subcategories node
array_push($category[“sub_categories”], $subcat);
}

array_push($categories[“Categories”], $category);

//print_r($category);

}echo ((isset($_GET[‘callback’])) ? $_GET[‘callback’] : “”) . ‘(‘ . json_encode($categories) . ‘)’;

?>

 

3rd leval categories

 

<?php

header(‘Content-Type: application/json’);
include’conn.php’;

$sql = mysql_query(“select * from isc_categories where catparentid=0 and catvisible=’1′”);
// parent categories node
$categories = array(“Categories” => array());

//print_r($categories);

while ($row = mysql_fetch_array($sql,MYSQL_ASSOC)) {
$cat_id = $row[‘categoryid’];
//print_r($row);
$ssql = mysql_query(“select * from isc_categories where catparentid=’$cat_id'”);

// single category node
$category = array(); // temp array
$category[“categoryid”] = $row[“categoryid”];
$category[“name”] = $row[“catname”];
$category[“sub_categories”] = array(); // subcategories again an array

while ($srow=mysql_fetch_array($ssql,MYSQL_ASSOC)) {
$subcat = array(); // temp array

$sid=$srow[‘categoryid’];
$subcat[“categoryid”] = $srow[‘categoryid’];
$subcat[“name”] = $srow[‘catname’];

$subcat[“sub_categories_3rd”] = array();
// $subcat[“sub_categories_3rd”] = array(‘Front’, ‘Rear’ );
$ssql12 = mysql_query(“select * from isc_categories where catparentid=’$sid'”);
while ($srow1=mysql_fetch_array($ssql12,MYSQL_ASSOC)) {
$subcat_3rd = array(); // temp array
$subcat_3rd[“categoryid”] = $srow1[‘categoryid’];
$subcat_3rd[“name”] = $srow1[‘catname’];
array_push( $subcat[“sub_categories_3rd”], $subcat_3rd);

}

/*$tssql = mysql_query(“select * from isc_categories where catparentid='”.$srow[‘categoryid’].”‘”);

while ($tsrow=mysql_fetch_array($tssql,MYSQL_ASSOC)) {
$thirdsub = array(); // temp array
$thirdsub[“status”] = $tsrow[‘catname’];

} array_push( $subcat, $thirdsub);
*/

// pushing sub category into subcategories node
array_push($category[“sub_categories”], $subcat);
}

array_push($categories[“Categories”], $category);

//print_r($category);

}echo ((isset($_GET[‘callback’])) ? $_GET[‘callback’] : “”) . ‘(‘ . json_encode($categories) . ‘)’;

?>

 

 

 

http://www.9lessons.info/2012/07/ecommerce-menu-design-with-json-data.html

http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

Advertisements
 
Leave a comment

Posted by on November 24, 2014 in Javascript

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: