Help me to fix the PHP code

Discussion in 'PHP' started by lenhhoxung, Dec 26, 2009.

  1. #1
    Dear Alls,

    I have just studied PHP program. Now I have a problem with my website.

    "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in"

    And here my code

    $result = mysql_query("SELECT a.brand_id as brand_id
    a.product_name as product_name
    b.brand_name as brand_name
    FROM product a, supplier b
    Where (a.brand_id=b.brand_id) AND (brand_id=$_GET[id])");// and (channel=($age)");


    The idea is that I will click on item from my website with brand_id=15, all products which have brand_id=15 will be displayed on the screen.

    Please help me

    Thks all & happy new year

    Sam
     
    Last edited: Dec 26, 2009
    lenhhoxung, Dec 26, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    this is the correct code $brand_id = $_GET[id];

    u seem to have forgot the ";"
     
    Bohra, Dec 26, 2009 IP
  3. Guthix121

    Guthix121 Well-Known Member

    Messages:
    1,078
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Add an ; after $_GET[id]
     
    Guthix121, Dec 26, 2009 IP
  4. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you very much
     
    lenhhoxung, Dec 26, 2009 IP
  5. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    <?php
    
    $brand_id = $_GET['id'];
    $result = mysql_query("SELECT * FROM supplier WHERE brand_id = $brand_id");
    
    ?>
    
    Code (PHP):
    OR

    
    <?php
    
    $brand_id = $_GET['id'];
    $result = mysql_query("SELECT * FROM supplier WHERE brand_id = $brand_id AND channel = $age");
    
    ?>
    
    Code (PHP):
     
    Last edited: Dec 26, 2009
    Brandon_R, Dec 26, 2009 IP
  6. lenhhoxung

    lenhhoxung Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    New one :((

    "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in"

    And here my code

    $result = mysql_query("SELECT a.brand_id as brand_id
    a.product_name as product_name
    b.brand_name as brand_name
    FROM product a, supplier b
    Where (a.brand_id=b.brand_id) AND (brand_id=$_GET[id])");// and (channel=($age)");


    The idea is that I will click on item from my website with brand_id=15, all products which have brand_id=15 will be displayed on the screen.

    Please help me

    Thks all & happy new year

    Sam
     
    lenhhoxung, Dec 26, 2009 IP
  7. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #7
    You're not getting that error from the code you posted. Post the full code.

    Brandon, both of your solutions would error.
     
    CoreyPeerFly, Dec 26, 2009 IP
  8. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #8
    Yea both ur codes dont have a ; and therefore will error
     
    Bohra, Dec 26, 2009 IP
  9. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Fixed. Thanks for letting my know.
     
    Brandon_R, Dec 26, 2009 IP
  10. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #10
    
    $result = mysql_query("
    	SELECT a.brand_id, a.product_name, b.brand_id, b.brand_name
    	FROM producta AS a
    	LEFT JOIN productb AS b ON (a.brand_id = b.brand_id)
    	WHERE brand_id = $brand_id
    ");
    [CODE]
    
    OR
    
    [CODE=PHP]
    $result = mysql_query("
    	SELECT a.brand_id, a.product_name, b.brand_id, b.brand_name
    	FROM producta AS a
    	LEFT JOIN productb AS b ON (a.brand_id = b.brand_id)
    	WHERE brand_id = $brand_id
    	AND channel = $age
    ");
    [CODE]
    
    For the above to work, both table  producta and productb will have to contain the field brand_id with a matching value to join both together.
    Code (PHP):
     
    Last edited: Dec 26, 2009
    Brandon_R, Dec 26, 2009 IP
  11. skilledphpcoder

    skilledphpcoder Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    check your mysql... some field is named wrong.
     
    skilledphpcoder, Dec 27, 2009 IP