Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP amateur need help for basic query.

    hey guys just wondering if i could get some help. i have a basic sql query
    my query runs fine and a get the results im looking for

    PHP Code:
        $data mysql_query("
        
                                SELECT a.AptDateTime,a.ProcDescript 
                                FROM appointment a
                                WHERE a.PatNum = '"
    .$search_query."'
                                ORDER BY a.AptDateTime DESC 
                                LIMIT 0 , 2
                                
                             "
    ); 

     while(
    $info mysql_fetch_array$data )) 
     {  
    echo 
    $info['ProcDescript']."<br>";

    but when i try and join the tabe with another table, instead of getting 2 results returned i get 1 result printed twice. just wondering if someone could tell me why.
    PHP Code:
    $data mysql_query("    
                                SELECT a.AptDateTime,a.ProcDescript
                                FROM appointment a
                                LEFT JOIN procedurelog p ON (a.PatNum=p.PatNum)
                                WHERE a.PatNum = '"
    .$search_query."'
                                ORDER BY a.AptDateTime DESC 
                                LIMIT 0 , 2
                                
                             "
    );
     
     while(
    $info mysql_fetch_array$data )) 
     {  
    echo 
    $info['ProcDescript']."<br>";

    thanks guys appreciate the help!

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    This is actually a MySQL issue, not a PHP one.

    When you do the join, you clearly have at least 2 rows in the procedurelog that match one row in appointment, and as you're only getting data from appointment, it seems like you're getting back the same data set twice.


  •  

    Posting Permissions

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