Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2005
    Posts
    306

    Quick Job 1 mysql question $1 US dollar

    i AM DESPERATE. anybody know how to use 1 select sentence to randomly get the results from photo table based on value of catid(no subid), i will pay


    Code:
    CREATE TABLE `".$db_prefix."subcat` (
    
    	subid INT(10) AUTO_INCREMENT NOT NULL,
    	catid INT(10) NOT NULL,
    
    	subname VARCHAR(15) NOT NULL,
    
    	PRIMARY KEY(subid)
    
    );
    
    
    CREATE TABLE `".$db_prefix."photo` (
    
    	photoid INT(20) AUTO_INCREMENT NOT NULL,
    
    	photoname VARCHAR(50) NOT NULL,
    
    	subid INT(10) NOT NULL,
    	userid INT(10) NOT NULL,
    
    	description TEXT,
    
    	level INT(2) NOT NULL DEFAULT '0',
    
    	uploadtime INT(15) NOT NULL DEFAULT '0',
    
    	PRIMARY KEY(photoid)
    
    );

  2. #2
    Join Date
    Sep 2004
    Location
    Flint, Michigan
    Posts
    5,765
    No need for money if it works:

    Code:
    SELECT * FROM photo WHERE `catid` = '5' ORDER BY RAND() LIMIT 1;
    Mike from Zoodia.com
    Professional web design and development services.
    In need of a fresh hosting design? See what premade designs we have in stock!
    Web design tips, tricks, and more at MichaelPruitt.com

  3. #3
    Join Date
    Mar 2005
    Posts
    306
    no, please see my database structure carefully
    in photo table there is no catid column

  4. #4
    Join Date
    Sep 2004
    Location
    Flint, Michigan
    Posts
    5,765
    Bleh sorry about that.

    SELECT * FROM subcat, photo WHERE photo.subid = subcat.subid AND subcat.catid = 5 ORDER BY RAND() LIMIT 1;

    edit as needed
    Mike from Zoodia.com
    Professional web design and development services.
    In need of a fresh hosting design? See what premade designs we have in stock!
    Web design tips, tricks, and more at MichaelPruitt.com

  5. #5
    Join Date
    Mar 2005
    Posts
    306
    thanks, give me paypal,if can work i will pay

  6. #6
    Join Date
    Sep 2004
    Location
    Flint, Michigan
    Posts
    5,765
    No need for money Just helping out a fellow WHTer.
    Mike from Zoodia.com
    Professional web design and development services.
    In need of a fresh hosting design? See what premade designs we have in stock!
    Web design tips, tricks, and more at MichaelPruitt.com

  7. #7
    Join Date
    Mar 2005
    Posts
    306
    thanks a lot

  8. #8
    I am not sure about what you mean by Randomly. But the SQL below will give you
    results from photo table based on value of catid:


    SELECT * FROM photo, subcat where photo.subid = subcat.subid and subcat.catid = "Enter your catid"

    You could add the follwowing as suggested by justadollorhosting:

    ORDER BY RAND() LIMIT 1;

Posting Permissions

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