Hi,
Consider the following:
<?
$username = "foo";
$password = "bar";
$host = "db";
$connect = odbc_connect("$ host", "$username" , "$password" ) or die;
$query = "SELECT id, name, address, city, state, comments1, comments2
FROM data.table1, data.table2 WHERE id = '795'";
$result = odbc_exec($conn ect, $query);
while(odbc_fetc h_row($result)) {
$id = odbc_result($re sult, 1);
$name = odbc_result($re sult, 2);
$address = odbc_result($re sult, 3);
$city = odbc_result($re sult, 4);
$state = odbc_result($re sult, 5);
$zip = odbc_result($re sult, 6);
$comments1 = odbc_result($re sult, 7);
$comments2 = odbc_result($re sult, 8);
print("ID: $id<br>Name: $name<br>Addres s: $address<br>Cit y:
$city<br>State: $state<br>Zip: $zip<br>Comment s1:
$comments1<br>C omments2: $comments2<br>\ n");
}
?>
Only one record is returned from data.table1 (containing the id, name,
address, city, state, & zip). However, there are multiple records
returned from data.table2 (records from comments1 & comments2). What
is happening is that when I run this script, all of the data returned
from data.table1 is printed over & over again along with each record
returned from data.table2. How can I make it such that id, name,
address, city, state & zip are only printed once - and allow comments1
& comments2 to be printed multiple times for each occurance in the
database?
I've thought about just creating a second database query for the
records in data.table2, however I need the join I'm getting by using
the existing query.
For what it's worth, I'm connecting to a DB2 database using PHP /
Apache on Linux.
I'm confused by this. Any help appreciated.
Thanks.
Consider the following:
<?
$username = "foo";
$password = "bar";
$host = "db";
$connect = odbc_connect("$ host", "$username" , "$password" ) or die;
$query = "SELECT id, name, address, city, state, comments1, comments2
FROM data.table1, data.table2 WHERE id = '795'";
$result = odbc_exec($conn ect, $query);
while(odbc_fetc h_row($result)) {
$id = odbc_result($re sult, 1);
$name = odbc_result($re sult, 2);
$address = odbc_result($re sult, 3);
$city = odbc_result($re sult, 4);
$state = odbc_result($re sult, 5);
$zip = odbc_result($re sult, 6);
$comments1 = odbc_result($re sult, 7);
$comments2 = odbc_result($re sult, 8);
print("ID: $id<br>Name: $name<br>Addres s: $address<br>Cit y:
$city<br>State: $state<br>Zip: $zip<br>Comment s1:
$comments1<br>C omments2: $comments2<br>\ n");
}
?>
Only one record is returned from data.table1 (containing the id, name,
address, city, state, & zip). However, there are multiple records
returned from data.table2 (records from comments1 & comments2). What
is happening is that when I run this script, all of the data returned
from data.table1 is printed over & over again along with each record
returned from data.table2. How can I make it such that id, name,
address, city, state & zip are only printed once - and allow comments1
& comments2 to be printed multiple times for each occurance in the
database?
I've thought about just creating a second database query for the
records in data.table2, however I need the join I'm getting by using
the existing query.
For what it's worth, I'm connecting to a DB2 database using PHP /
Apache on Linux.
I'm confused by this. Any help appreciated.
Thanks.
Comment