473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ODBC Query Results

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($connect, $query);

while(odbc_fetch_row($result)){
$id = odbc_result($result, 1);
$name = odbc_result($result, 2);
$address = odbc_result($result, 3);
$city = odbc_result($result, 4);
$state = odbc_result($result, 5);
$zip = odbc_result($result, 6);
$comments1 = odbc_result($result, 7);
$comments2 = odbc_result($result, 8);
print("ID: $id<br>Name: $name<br>Address: $address<br>City:
$city<br>State: $state<br>Zip: $zip<br>Comments1:
$comments1<br>Comments2: $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.

Jul 17 '05 #1
2 2286

"Mike Poe" <tr**************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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($connect, $query);

while(odbc_fetch_row($result)){
$id = odbc_result($result, 1);
$name = odbc_result($result, 2);
$address = odbc_result($result, 3);
$city = odbc_result($result, 4);
$state = odbc_result($result, 5);
$zip = odbc_result($result, 6);
$comments1 = odbc_result($result, 7);
$comments2 = odbc_result($result, 8);
print("ID: $id<br>Name: $name<br>Address: $address<br>City:
$city<br>State: $state<br>Zip: $zip<br>Comments1:
$comments1<br>Comments2: $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.


If the var $id is unique then you could use,
$result = odbc_exec($connect, $query);

while(odbc_fetch_row($result)){
$id = odbc_result($result, 1);
$name = odbc_result($result, 2);
$address = odbc_result($result, 3);
$city = odbc_result($result, 4);
$state = odbc_result($result, 5);
$zip = odbc_result($result, 6);
$comments1 = odbc_result($result, 7);
$comments2 = odbc_result($result, 8);
if ($id == $last_id){
print("Comments1:$comments1<br>Comments2: $comments2<br>\n");
}
else {
print("ID: $id<br>Name: $name<br>Address:
$address<br>City:$city<br>State: $state<br>Zip:
$zip<br>Comments1:$comments1<br>Comments2: $comments2<br>\n");
}
$last_id = $id;

}

Brent Palmer.
Jul 17 '05 #2

Brent Palmer wrote:
"Mike Poe" <tr**************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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($connect, $query);

while(odbc_fetch_row($result)){
$id = odbc_result($result, 1);
$name = odbc_result($result, 2);
$address = odbc_result($result, 3);
$city = odbc_result($result, 4);
$state = odbc_result($result, 5);
$zip = odbc_result($result, 6);
$comments1 = odbc_result($result, 7);
$comments2 = odbc_result($result, 8);
print("ID: $id<br>Name: $name<br>Address: $address<br>City: $city<br>State: $state<br>Zip: $zip<br>Comments1:
$comments1<br>Comments2: $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.

If the var $id is unique then you could use,
$result = odbc_exec($connect, $query);

while(odbc_fetch_row($result)){
$id = odbc_result($result, 1);
$name = odbc_result($result, 2);
$address = odbc_result($result, 3);
$city = odbc_result($result, 4);
$state = odbc_result($result, 5);
$zip = odbc_result($result, 6);
$comments1 = odbc_result($result, 7);
$comments2 = odbc_result($result, 8);
if ($id == $last_id){
print("Comments1:$comments1<br>Comments2:

$comments2<br>\n"); }
else {
print("ID: $id<br>Name: $name<br>Address:
$address<br>City:$city<br>State: $state<br>Zip:
$zip<br>Comments1:$comments1<br>Comments2: $comments2<br>\n");
}
$last_id = $id;

}

Brent Palmer.


Great Brent, thanks! That seems to work beautifully.

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Graham | last post by:
I need a SQL Server or ODBC package for Python. Can anyone help please? Have search the Python packages under Database and there is no reference to either SQL Server or ODBC. Thanks Graham
11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
3
by: Wescotte | last post by:
I'm working with IBM's Client Access ODBC Driver version 8.00.08.00 5/8/2001 installed with Client Access Express V5R1M0. The issue is if I execute the exact same select statement more than...
3
by: Ian | last post by:
We are currently experiencing problems with our Access XP database. We are using access as the front-end and are connecting to Oracle 7.3 via ODBC. Our users are running Win 98 and Win Xp. We are...
8
by: Alfonso Esteban Gonzalez Sencion | last post by:
I am trying to use Access as a front end for extracting information from an Oracle database. I started using linked tables but I am getting a very curious behaviour. When I consult the linked...
7
by: Joe | last post by:
I am using Access 2003 and are linking to an Oracle 9i ODBC datasource (using Oracle ODBC drivers). After linking the tables in Access, I inspect the data contained in the linked tables. For...
4
by: Dave | last post by:
Hey guys, I have an ODBC problem that has me stumped. I wrote a VBA script to run in Microsoft Excel that pulls data out of an application using that application's ODBC driver and puts it into...
1
by: RLN | last post by:
RE: Access 2003 using WinXP SP2 Problem: When I start up my app I double click either one of my two Oracle tables in the table list, it asks for an id and pass. I need them to be linked at...
1
by: zxo102 | last post by:
Hi everyone, I need your help for using python odbc module. I have a simple table defined as create table A ( userId char(10), courseid char(10), grade integer, primary key(userId,courseId)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.