A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Some help with some MySQL and PHP code please

  1. #1
    Senior Member
    Join Date
    Feb 2007
    Posts
    153

    Some help with some MySQL and PHP code please

    Let's say that I have the following 4 tables in my database:

    users (id, username)
    products (id, name, image)
    selling (sellid, productid, price)
    sold (userid, productid, sellid)

    I want so select the first 5 rows from the "sold" table and to retrieve the username, the product name, the product image and the product price.

    The username will be retrieved by comparing sold.userid with users.id.

    The product name will be retrieved by comparing sold.productid with products.id and taking the name.

    Same for the product image.

    And the product price will be retrieved by comparing sold.sellid with selling.sellid and taking the price.

    What would be the MySQL code for retrieving the 5 rows with the appropriate information and the PHP code to echo this information ?

    Thank you.

  2. #2
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    SELECT s.id as sold_id, u.id as user_id, p.id as products_id, p.name as product_name, p.image as product_image
    FROM sold s
    INNER JOIN users u
    ON u.id=s.userid
    INNER JOIN products p
    ON p.id=s.productid
    LIMIT 5;

    something like that.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center