Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 2nd, 2003, 02:49 PM
hatimad hatimad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Dallas
Posts: 25 hatimad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP -Output in table

Hello,

i posted this in PHP forum and someone told me to post it somewhere else.

someone please help

i have this code
PHP Code:
<!-- subcategories //-->

<?php
function show_subcategories($counter
{
    global 
$fooa$subcategories_string$id$HTTP_GET_VARS;
    
$cPath_new 'cPath=' $fooa[$counter]['path'];
    
    
$subcategories_string .= '<a href="';
    
$subcategories_string .= tep_href_link(FILENAME_DEFAULT$cPath_new);
    
$subcategories_string .= '"  class="headerNavigation">';
    
    
// display category name
    
$subcategories_string .= $fooa[$counter]['name'];
    
    
$subcategories_string .= '</a> ';
    
    if (
$fooa[$counter]['next_id']) {
        
$subcategories_string .= '<br>';
        
show_subcategories($fooa[$counter]['next_id']);
    }else{
        
$subcategories_string .= '&nbsp;';
    }
}
?>
<?php
if ($cPath != '') {
$cPath=$cPath;
} else {
$cPath tep_get_path_for_tab(tep_get_products_catagory_id($HTTP_GET_VARS['products_id']));
}
    if (
$cPath) {
        
$subcategories_string '';
        
$new_path '';
        
$id split('_'$cPath);
        
reset($id);
        while (list(
$key$value) = each($id)) {
            unset(
$prev_id);
            unset(
$first_id);
            
$subcategories_query tep_db_query("select c.categories_id, cd.categories_name, c.parent_id 
from " 
TABLE_CATEGORIES " c, " TABLE_CATEGORIES_DESCRIPTION " cd 
where c.parent_id = '" 
$value "' and c.categories_id = cd.categories_id 
and cd.language_id='" 
$languages_id ."' order by sort_order, cd.categories_name");
            
$subcategory_check tep_db_num_rows($subcategories_query);
            if (
$subcategory_check 0) {
                
$new_path .= $value;
                while (
$row tep_db_fetch_array($subcategories_query)) {
                    
$fooa[$row['categories_id']] = array(
                        
'name' => $row['categories_name'],
                        
'parent' => $row['parent_id'],
                        
'level' => $key+1,
                        
'path' => $new_path '_' $row['categories_id'],
                        
'next_id' => false
                    
);
                    if (isset(
$prev_id)) {
                        
$fooa[$prev_id]['next_id'] = $row['categories_id'];
                    }
    
                    
$prev_id $row['categories_id'];
                    
                    if (!isset(
$first_id)) {
                        
$first_id $row['categories_id'];
                    }
    
                    
$last_id $row['categories_id'];
                }
                
$fooa[$last_id]['next_id'] = $fooa[$value]['next_id'];
                
$fooa[$value]['next_id'] = $first_id;
                
$new_path .= '_';
            } else {
                break;
            }
        }
    }
    if (
$id[0] != ''){
        
show_subcategories($id[0]);
        echo 
$subcategories_string;
    }else{
        echo 
"&nbsp;";
    }


?>
<!-- subcategories_eof //--> 


it gives me output like

subcategory1
subcategory2
subcategory3
subcategory4
subcategory5
subcategory6
subcategory7
subcategory8
subcategory9

how can i modify this to give output in a table to show it like

subcategory 1 subcategory 5 subcategory 9
subcategory 2 subcategory 6 subcategory 10
subcategory 3 subcategory 7 etc.
subcategory 4 subcategory 8 etc..


thanks in advance

Hats

Reply With Quote
  #2  
Old April 5th, 2003, 11:29 AM
Mirax's Avatar
Mirax Mirax is offline
Senior Member
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2000
Location: Enschede, The Netherlands
Posts: 1,527 Mirax User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 49 m 2 sec
Reputation Power: 10
That WHOLE code just returns a list of subcategories?!? Yeez.. (didn't read it's too long imo )

First of all, I think this belongs in the PHP forum since it's (1) PHP and (2) more compicated than much stuff around there.. anyway..

General advice: KISS (Keep it simple, stupid)

Start with an array with x elements and use it as the data you want to put in the table... Forget the database for now since that's just 'information', not 'structure'...
Since tables are created by row and each row is created from left to right it's easier to order your subcategories like
Quote:
subcat 1 | subcat 2 | subcat 3
subcat 4 | subcat 5 | subcat 6
subcat 7 | subcat 8 | subcat 9
subcat 10 | ...
If this is also fine, search the php forum for 'generate table' or 'dynamic table' and you should find some code examples there..

If you want the order you mentioned you'll have to count the amount of subcats in the beginning. Check how much subcats remain if you devide it by X (X is the amount of columns). If the amount is dividable by X all columns will have the same amount of rows (Y), if not you'll need to make the columns 1 row longer then the number of times X 'fits' in the total amounts of subcats (being Y).... still following me??
Then create a table with 1 row and 3 cols. In the first cell you make another table with the subcats 1 to Y. In the second you make a table with the subcats Y+1 to 2Y etc...

If the information of one of the subcat takes more place then another the total table will become 'messy'. Other solution would be to use a single table and calculate which subcat is supposed to be in each following cell: 1, Y+1, 2Y+1, 2, Y+2, 2Y+2 etc...

Hope this is of some help

Regards
__________________
There are 10 types of people in this world - those who understand binary and those who don't...

PHP | MySQL | DevShed Forum Search | Google Search

Reply With Quote
  #3  
Old April 5th, 2003, 12:06 PM
hatimad hatimad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Dallas
Posts: 25 hatimad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

thank you for your reply

first let me appologise, i found the solution from PHP forum, i should have posted it here for anyone who wants to use it

here is the Link to the solution, person who told me to post this in somewhere else and not in PHP,
actually wrote a function for me which gives output in the form i wanted

Cheers!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > PHP -Output in table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT