Hi All --
I recently converted over to using ADODB instead of php's MySQL functions but I'm having some problems with the logic... Prior to ADODB, I could get the results of a query and then kick off another query based on those results... but with ADODB this ability seems to have escaped me. Example:
Say I have 2 tables:
table1
id | col1 | col2
1 | item1| item2
2| item1| item2
3| item1| item2
table2
id | col1 | col2
1 | somthing1| somthing2
2 | somthing1| somthing2
3 | somthing1| somthing2
Using php's MySQL functions I could:
$query = "
SELECT *
FROM table1";
$result = mysql_query($query) or die (mysql_errror());
$array= mysql_fetch_assoc($result);
// Another query to get additional data
$query = "
SELECT *
FROM table2
WHERE id = '". $array['id']."'";
$result = mysql_query($query) or die (mysql_errror());
$moredata = mysql_fetch_assoc($result);
// display results....
Now here's the problem with ADODB... if there are more then 2 columns, a multi-dimensional array is returned...
$query = "
SELECT *
FROM table1";
$result = $dbc->GetAssoc($query);
echo $result['id'];
// nothing displayed so i cant do another query based on my primary key.
print_r($result);
Array
(
[1] => Array
(
[col1] => item1
[col2] => item2
)
[2] => Array
(
[col1] => item1
[col2] => item2
)
)
The first column becomes the index... so how could I use that in a query?
Something like:
$query = "
SELECT *
FROM table2
WHERE id = $result[?][somthing1]
If the above makes sense to anyone, how would I go about doing this? After searching around, seems like JOIN might be my answer... never used it though.
Any tips, suggestions 😕
Thanks!
- Chris
EDIT:
I ended up doing a foreach before any additional queries...