Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

 

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
New Webmasters ask "How-To" questions here. This is where other fucking Webmasters help.

 
Thread Tools
Old 07-30-2009, 11:54 PM   #1
adulttemps
Confirmed User
 
Industry Role:
Join Date: May 2002
Location: Brentwood,TN Heredia, Costa Rica
Posts: 320
PHP Question

I have the following function

PHP Code:
function categories () {
    
    
    
    
$res mysql_query('select category from content ORDER BY category');
    while(
$rows mysql_fetch_array($res)){
    
        
        
$a = array();
        
        foreach (
$rows as $row)
        {
        
$foo explode(','$row);

        
$a array_merge($a$foo);
        

        echo 
'<li><a href="/videos/'.$a[0].'" title="'.$a[0].'">'.$a[0].'</a></li>';
                
        }
    }    
    

It selects the categories out fine, but how do i get it to only display unique categories?

This prints each category everytime its listed in the db I cant use select distinct because some categories contain more than one category : example anal, amateur, blowjob
__________________
Hillipino Money with Cams
adulttemps is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 07-31-2009, 12:32 AM   #2
Ferrishyn
Registered User
 
Join Date: Nov 2005
Posts: 28
This should work for ya:
Quote:
$res = mysql_query('select distinct(category) from content ORDER BY category');
Ferrishyn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 07-31-2009, 12:35 AM   #3
Ferrishyn
Registered User
 
Join Date: Nov 2005
Posts: 28
That's what I get for posting this early in the morning, I didn't read it ;)

You need to separate that out so its not in the same field like that. You could also read through all of them explode them by the commas and unique that array.

Last edited by Ferrishyn; 07-31-2009 at 12:36 AM..
Ferrishyn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 07-31-2009, 03:36 AM   #4
webboy21
Confirmed User
 
Industry Role:
Join Date: Nov 2004
Location: The Netherlands
Posts: 573
well your problem is bad database design ;) basically what ferrishyn said....his solution will work too....but it's better to start at the source and build up your database the right way
__________________
Available for: CSS | XHTML | PHP | MySQL | Webdesign

webboy21 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 07-31-2009, 07:46 AM   #5
adulttemps
Confirmed User
 
Industry Role:
Join Date: May 2002
Location: Brentwood,TN Heredia, Costa Rica
Posts: 320
Yea the database design is from an affiliate dump, they dump the categories seperated by commas.
__________________
Hillipino Money with Cams
adulttemps is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 07-31-2009, 06:08 PM   #6
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
Old 07-31-2009, 11:20 PM   #7
Kaylum
Confirmed User
 
Industry Role:
Join Date: Aug 2005
Location: Costa Rica
Posts: 465
update:

replace ($category) in the echo statement to ($element) which holds the category.

peace
__________________
-- "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
 
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.