开发者

PHP ODBC SQL JOIN

A company recently asked me to bridge the multiple databases they have with some PHP. While most of their new databases are MySQL, they have one that is a PROGRESS database. Everything was going good until I ran into a slight error.

The code runs great except that j.JobNum returns the following error:

Field j.JobNum not found in LOCATION

If I remove the last JOIN it works fine. The same happens for any overlapping fields. If rows overlap they cant be outputted.

$table_name = "Customer";
$fields = 'j.JobNum, Name, City, State, Zip';

$conn = odbc_connect($dsn, $username, $password, SQL_CUR_USE_ODBC);

$field_array = explode(', ', $fields);

$sql = "SELECT TOP 50 ".$fields." FROM PUB.JobProd j LEFT JOIN PUB.BookOrd b ON j.OrderNum=b.OrderNum LEFT JOIN PUB.Customer c ON b.Cust开发者_StackOverflow中文版Num=c.CustNum LEFT JOIN PUB.JobHead jh ON j.JobNum=jh.JobNum";
    echo '<table>';
    echo '<tr><td>JobNum</td><td>Name</td><td>City</td><td>State</td><td>Zip</td></tr>';
    $rs = odbc_exec($conn,$sql) or die('Select failed!');
        while(odbc_fetch_row($rs)){
            echo '<tr>';
            foreach($field_array as $key=>$field){
                echo "<td>".odbc_result($rs, $field)."</td>";
            }
            echo '</tr>';
        }
    echo '</table>';      
odbc_close($conn);

Is there a solution for this? Is something wrong with my code?


Try to do this

$sql = "SELECT TOP 50 ".$fields." FROM PUB.JobProd AS j LEFT JOIN PUB.BookOrd AS b 
ON j.OrderNum=b.OrderNum LEFT JOIN PUB.Customer AS c 
ON b.CustNum=c.CustNum LEFT JOIN PUB.JobHead AS jh 
ON j.JobNum=jh.JobNum";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜