Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Query multiple MySQL tables with PHP

  1. #11
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    SELECT p.NAME, pp.PRICE FROM
    you have only asked it to select the name and the price, if you need something else selected you need to add them to the select

  2. #12
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    "SELECT p.NAME, pp.PRICE FROM product AS p LEFT JOIN productprogram AS pp ON p.PRODUCTID = pp.PRODUCTID WHERE p.PRODUCTID = '$id'"

    it seems there WHERE has no effect on which entry it selects
    Whether I do the above or change it to:

    "SELECT p.NAME, p.PRODUCTID, pp.PRICE FROM product AS p LEFT JOIN productprogram AS pp ON p.PRODUCTID = pp.PRODUCTID WHERE p.PRODUCTID = '$id'"

    It still only selects the first record in the table.

  3. #13
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    do you have some example output? or a site that can link us to an example?

    also print out the exact query that it is generating. that may help in understanding why its not returning the full result set

    the other thing would be to go into your SQL manager, and try to run the query and see what is returned.

    if there are any errors produced please post those as well.

    another thing to test is to do a query like

    Code:
    SELECT p.*, pp.* FROM product AS p LEFT JOIN productprogram AS pp ON p.PRODUCTID = pp.PRODUCTID WHERE p.PRODUCTID = '$id';
    and plug in some actual values for the $id. that query should return every field that describe each record (data entry)
    Last edited by boogyman; 10-18-2007 at 01:37 PM.

  4. #14
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    I have finally cracked it!
    Thanks very much for all your help!

  5. #15
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    congrats, what ended up being the problem?

  6. #16
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    not entirely sure but I did as you suggested and ran the query through my SQL manager, that didn't work but I was able to change the code easily from there.

    ended up changing it to this:

    $sql = "SELECT product.NAME, productprogram.PRICE FROM product LEFT JOIN productprogram ON product.PRODUCTID = productprogram.PRODUCTID WHERE product.PRODUCTID = '$id'";

    I don't know if it's better to have aliases or not but once I used this code everything worked perfectly!

    Thanks again for your help! Much appriciated.

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
  •