Current location: Hot Scripts Forums » Programming Languages » PHP » Generating external js subcategory list from MySQL using PHP


Generating external js subcategory list from MySQL using PHP

Reply
  #1 (permalink)  
Old 12-15-03, 10:08 AM
NanoEntity NanoEntity is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Generating external js subcategory list from MySQL using PHP

Quote:
What I want to generate is a list to something like this, this is only an example what I want, if anyone would be so kind and help me here that would be great.

PHP Code:

var subcatArray = new Array(2);
subcatArray[1] = new Array(
 new Array(
'2''SubCategory 1 order 1'),
 new Array(
'5''SubCategory 1 order 2')
);
subcatArray[2] = new Array(
 new Array(
'4''SubCategory 2 order 1'),
); 
----------------------------------------------------------
Generated JS currentually
PHP Code:

var subcatArray = new Array(3);
 
subcat[] = new subcat(2'SubCategory 1 order 1');
 
subcat[] = new subcat(5'SubCategory 1 order 2');
 
subcat[] = new subcat(4'SubCategory 2 order 1'); 

SCRIPT RUNING - .php?type=js
PHP Code:

<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
'./includes/functions_external.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
// chosen forums
$forums $DB->query("
 SELECT title, forumid
 FROM " 
TABLE_PREFIX "forum
 WHERE parentid > -1
 ORDER BY parentid,displayorder
"
);

$forumcache = array();
while (
$forum $DB_site->fetch_array($forums))
// fetch the forums
 
$forumcache[] = $forum;
}

$_REQUEST['type'] = strtoupper($_REQUEST['type']);
switch (
$_REQUEST['type'])
{
 case 
'JS':
 case 
'XML':
 case 
'RSS2':
  break;
 default:
  
$_REQUEST['type'] = 'JS';
}

if (
$_REQUEST['type'] == 'JS')
// javascript output

 
echo "var subcatArray = new Array(" sizeof ($forumcache) . ");\r\n";
 if (!empty(
$forumcache))
 {
  foreach (
$forumcache AS $subcat)
  {
   
$subcat['title'] = addslashes_js($subcat['title']);
   echo 
"\tsubcat[] = new subcat($subcat[forumid], '$subcat[title]');\r\n";
  }
 }

}

?>
SQL Query
PHP Code:

CREATE TABLE `forum` (
  `
forumidsmallint(5unsigned NOT NULL auto_increment,
  `
titlevarchar(100NOT NULL default '',
  `
displayordersmallint(6NOT NULL default '0',
  `
parentidsmallint(6NOT NULL default '0',
  `
parentlistvarchar(250NOT NULL default '',
  `
childlistvarchar(250NOT NULL default '',
  
PRIMARY KEY  (`forumid`)
TYPE=MyISAM AUTO_INCREMENT=;

#
# Dumping data for table `forum`
#

INSERT INTO `forumVALUES (1'Main Category 1'1, -1'1,-1''1,2,5,-1');
INSERT INTO `forumVALUES (2'SubCategory 1 order 1'11'2,1,-1''2,-1');
INSERT INTO `forumVALUES (5'SubCategory 1 order 2'21'5,1,-1''5,-1');
INSERT INTO `forumVALUES (3'Main Category 2'2, -1'3,-1''3,4,6,-1');
INSERT INTO `forumVALUES (4'SubCategory 2 order 1'13'4,3,-1''4,-1'); 
----------------------------------------------------------
__________________
NO IMAGINATION... NO LIFE... NO FUTURE...
http://artwork.hololith.com/sigs.php

Last edited by NanoEntity; 12-15-03 at 10:22 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
best mailing list php script heysherman Script Requests 13 05-04-04 01:56 PM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 04:31 AM
MySQL with PHP question. HELP for a newbie kenfused PHP 3 08-02-03 01:53 AM
Free PHP, Perl and possible mySQL hosting! toby General Advertisements 8 06-17-03 02:04 AM


All times are GMT -5. The time now is 10:41 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.