Results 1 to 8 of 8

Thread: Need random list by category

  1. #1
    Harkster is offline Registered User
    Join Date
    Mar 2008
    Posts
    127

    Default Need random list by category

    Code:
      $tpl = new Template;
      $sp_expire = date('Y-m-d H:i:s');
    	$query = "
    	select * from idx_link 
      left join idx_paid_listing on (idx_link.link_id = idx_paid_listing.link_id) 
    	where sponsored = 1 and expire > '$sp_expire'
        order by rand() limit 5";
      $sp_links = $dbConn->FetchArray($query);
    is from clock.sponsor and works nicely but not what I want.

    Since I am not good with sql I am stuck.

    For top level categories only I would like to select rand some number of sponsor, featured or basic. This list needs to consist of only those resources which exist in the subcategories of the top level category.

    Since the parent list is basically a ; separated list is this going to have to be a 2 or more step process?

    Anyone please?

  2. #2
    FSGDAG's Avatar
    FSGDAG is offline Moderator
    Join Date
    May 2007
    Location
    NJ, United States
    Posts
    1,651

    Default

    This one appears to be above my pay grade ( Incase anyone was wondering, pay grade = $0.00 ).

    Hopefully pungky or maulana can chime in on this
    FSGDAG | IndexU Hosting | Owner
    Website | NiceCoder Script Hosting and More! | Web4URL is For Sale!
    Follow Us On Twitter | FaceBook Profile | YouTube Videos

  3. #3
    dody is offline Administrator
    Join Date
    Aug 2001
    Location
    Indonesia
    Posts
    3,731

    Default

    Pungky is working on it now.
    www.nicecoder.com
    www.dodyrw.com

  4. #4
    Harkster is offline Registered User
    Join Date
    Mar 2008
    Posts
    127

    Default

    Quote Originally Posted by dody View Post
    Pungky is working on it now.
    Thanks, I think I could get it done but can't figure a good way to deal with that idx_categories_path parents field structure. Can't find an SQL thing for existence of a 'substring'; but then I am an SQL dummy.

  5. #5
    pungky's Avatar
    pungky is offline Super Moderator
    Join Date
    Mar 2009
    Posts
    143

    Default

    Hi, please download this attachment file.
    Attached Files Attached Files

  6. #6
    Harkster is offline Registered User
    Join Date
    Mar 2008
    Posts
    127

    Default

    That was quick. I am having a health issue to work through but can't wait to try it out.

    2 small questions please.
    1. best way to test for top level category in browse?
    2. I thought there was a way to disallow submissions in top categories. Yes/No?

  7. #7
    Harkster is offline Registered User
    Join Date
    Mar 2008
    Posts
    127

    Default

    Works good but I need it to only execute for top level category.

    After bumming around here I thought the following would work but...

    Added $parent as global in browse.php @ line 24

    In browse.html
    Code:
            <%if $parent == 0%>
              <!-- random links in this category -->
              <%block_view_random_list_by_category category_id="$cat" max_item="10" template="block.view_random_list_by_category.html"%>
    		<%/if%>
    What am I missing?

  8. #8
    Harkster is offline Registered User
    Join Date
    Mar 2008
    Posts
    127

    Default

    Ok, after spending hours without coming up with how to test for parent_id in the block html I decided to take a brute force approach.

    Again, hours trying to find a function for this I finally (after many dead ends/errors) I did this.

    In the block php I inserted:
    Code:
        $children = $category_obj->GetChildren($cat);
    
    // This to find parent - if parent not zero skip everything	
      $query = "select parent_id from idx_category where category_id = ".$cat;
      $res = $dbConn->Execute($query);
      $p = $res->Fields("parent_id");
    if ($p == 0) {
    // Execute if parent is zero  
        if (is_array($children)) {
    Well, it works but I would like to know if anyone has a better/cleaner way.

Similar Threads

  1. How to list the random listing block horizontally
    By Mitchell in forum Blocks and Modification
    Replies: 14
    Last Post: 04-22-2008, 09:32 AM
  2. Image map for IndexU category list
    By Bruceper in forum Blocks and Modification
    Replies: 6
    Last Post: 01-29-2008, 01:30 AM
  3. Imagemap for IndexU category list (Canadian Provinces & Cities)
    By Bruceper in forum Blocks and Modification
    Replies: 0
    Last Post: 01-28-2008, 04:04 PM
  4. Random Links from A Specific Category
    By infiniteflow in forum Blocks and Modification
    Replies: 0
    Last Post: 11-23-2007, 01:47 PM
  5. Random Links & Category Display
    By clickwilmington in forum v5.x
    Replies: 1
    Last Post: 08-20-2006, 08:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •