SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Smolf3d's Avatar
    Join Date
    Aug 2004
    Location
    russia
    Posts
    224
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Help with query from 2 tables (php/mysql)

    table one (production)

    Code MySQL:
    SELECT id, name, image FROM production WHERE catname = '".$show_cat."' ORDER BY RAND() DESC

    table two (prices) (Can be more when one price of product id)

    Code MySQL:
    SELECT product_price, product_weight FROM prices WHERE product_id = '".$id."'

    I need to do


    Code:
    .-------------------------------------------------------
    | ID |  PRODUCT  |  PRICE | AND OTHER INFORMATION ....
     -------------------------------------------------------
    | 1  | Milk      |  1000  |
     -------------------------------------------------------
    | 2  | Beer      |  1000  |
    |    |           |  1500  |
    |    |           |  2500  |
     -------------------------------------------------------
    thanks (sorry for my english)

  2. #2
    SitePoint Addict Smolf3d's Avatar
    Join Date
    Aug 2004
    Location
    russia
    Posts
    224
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    sorry i thing i need php more help when mysql

    Code MySQL:
    SELECT production.id
         , production.name
         , production.image
         , price_product.product_price AS price
         , price_product.product_weight AS weight
      FROM production
    LEFT OUTER
      JOIN prices AS price_product
        ON price_product.product_id = production.id
    ORDER 
        BY production.id

    it's ok ? (if yes need php help) :-(

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Smolf3d View Post
    it's ok ?
    what happened when you tested it? ™

    hint: yes it is

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    @Smolf3d ; Don't forget that any user-submitted data must be sanitized before being allowed anywhere near to the database. The best way is by using prepared statements
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Addict Smolf3d's Avatar
    Join Date
    Aug 2004
    Location
    russia
    Posts
    224
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    After some tests i found the problem, this is not mysql .... php :-(

    Now work perfect , but thanks for replies :-) And SpacePhoenix yep i know )))


Bookmarks

Posting Permissions

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