mysql join

Discussion in 'PHP' started by promotingspace.net, Mar 20, 2010.

  1. #1
    Hi
    Please tell me this code is correct:
     
    $query=SELECT res_restaurents.restaurentName, res_restaurents.restaurentZip , res_restaurents.restaurentCity , res_restaurents.restaurentState , res_restaurents.restaurentCountry ,res_restaurents.iD , coupons_menus.res_id, coupons_menus.couponname ,coupons_menus.code ,coupons_menus.details FROM res_restaurents, coupons_menus WHERE res_restaurents.iD=coupons_menus.res_id     
     
    $result=mysql_query($query) or die(mysql_error());
    echo mysql_num_rows($result);
    while($row=mysql_fetch_array($result)){
    echo $row['coupons_menus.couponname']." is for ".$row['res_restaurents.iD'];
     
    }
     
    PHP:
    mysql_num_rows returns 4 but no data is visable
    Thank you
     
    promotingspace.net, Mar 20, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi, try:
    $query='SELECT res_restaurents.restaurentName,
    res_restaurents.restaurentZip,
    res_restaurents.restaurentCity,
    res_restaurents.restaurentState,
    res_restaurents.restaurentCountry,
    res_restaurents.iD,
    coupons_menus.res_id,
    coupons_menus.couponname,
    coupons_menus.code,
    coupons_menus.details FROM res_restaurents,coupons_menus 
    WHERE res_restaurents.iD=coupons_menus.res_id';
     
    $result=mysql_query($query) or die(mysql_error());
    echo mysql_num_rows($result)."<br />";
    while($row=mysql_fetch_array($result)) echo $row['couponname'].' is for '.$row['iD'].'<br /><br />'; 
    
    PHP:
    Regards :)
     
    koko5, Mar 20, 2010 IP
  3. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    worked Thanks
     
    promotingspace.net, Mar 20, 2010 IP