Thread: PHP Question
View Single Post
Old 07-31-2009, 06:08 PM  
Kaylum
Confirmed User
 
Industry Role:
Join Date: Aug 2005
Location: Costa Rica
Posts: 465
yo, a quick hack to get your stuff working...

note: that select statement gives the impression that the categories are already stored in the database as one category per row, but i guess not.

PHP Code:
function categories () {
    
    
    
    
$res mysql_query('select category from content ORDER BY category');
    while(
$rows mysql_fetch_array($res)){
    
        
        
$dirty_array = array();
        
$clean_array = array();

        foreach (
$rows as $row)
        {
        
$foo explode(','$row);

        
$dirty_array array_merge($dirty_array$foo);
                 
        }

        
// loop through the crappy array
        
foreach ($dirty_array as $element)
       {
            
// quick hack to bypass duplicates
           
if (!in_array($element,$clean_array)
          {
                    
// push the category element into array
                    
array_push($clean_array,$element); 
                    
                    
// quick hack to print out links without re-looping through clean-array
                    
echo '<li><a href="/videos/'.$category.'" title="'.$category.'">'.$category.'</a></li>';
          }
       }
    }    
    

__________________
-- "You can't stop ingenuity, trust me.."
Kaylum is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook