Retrieving data from MySQL in one SQL statement

Posted by james.ingham on Stack Overflow See other posts from Stack Overflow or by james.ingham
Published on 2009-09-03T15:35:30Z Indexed on 2010/04/07 22:13 UTC
Read the original article Hit count: 265

Filed under:
|
|
|

Hi all,

If I'm getting my data from Mysql like so:

    $result = $dbConnector->Query("SELECT * FROM branches, businesses WHERE branches.BusinessId = businesses.Id ORDER BY businesses.Name");
    $resultNum = $dbConnector->GetNumRows($result);
    if($resultNum > 0)
    {
        for($i=0; $i < $resultNum; $i++)
        {
            $row = $dbConnector->FetchArray($result);
            // $row['businesses.Name'];
            // $row['branches.Name'];
            echo $row['Name'];
        }
    }

Does anyone know how to print the field Name in businesses and how to print the name from branches?

My only other alternative is to rename the fields or to call Mysql with two seperate queries.

Thanks in advance

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql