Sunday, 25 August 2013

writing a second query based on results of the first - Not working

writing a second query based on results of the first - Not working

Gentlemen and Ladies,
*Mysql will be upgraded later.
Preface: Authors can register in two languages and, for various additional
reasons, that meant 2 databases. We realize that the setup appears odd in
the use of multiple databases but it is more this abbreviated explanation
that makes it seem so. So please ignore that oddity.
Situation: My first query produces a recordset of authors who have
cancelled their subscription. It finds them in the first database.
require_once('ConnString/FirstAuth.php');
mysql_select_db($xxxxx, $xxxxxx);
$query_Recordset1 = "SELECT auth_email FROM Authors WHERE Cancel = 'Cancel'";
$Recordset1 = mysql_query($query_Recordset1, $xxxxxx) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
In the second db where they are also listed, (table and column names are
identical) I want to update them because they cancelled. To select their
records for updating, I want to take the first recordset, put it into an
array, swap out the connStrings, then search using that array.
These also work.
$results = array();
do {
results[] = $row_Recordset1;
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
print_r($results);
gives me an array. Array ( [0] => Array ( [auth_email] =>
renault@autxxx.com ) [1] => Array ( [auth_email] => rinaldi@autxxx.com )
[2] => Array ( [auth_email] => hemingway@autxxx.com )) ...so I know it is
finding the first set of data.
Here's the problem: The query of the second database looks for the author
by auth_email if it is 'IN' the $results array, but it is not finding the
authors in the 2nd database as I expected. Please note the different
connString
require_once('ConnString/SecondAuth.php');
mysql_select_db($xxxxx, $xxxxxx);
$query_Recordset2 = "SELECT auth_email FROM Authors WHERE auth_email
IN('$results')";
$Recordset2 = mysql_query($query_Recordset2, $xxxxxx) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
The var_dump is 0 but I know that there are two records in there that
should be found. I've tried various combinations of IN like {$results},
but when I got to "'$results'", it was time to ask for help. I've checked
all the available posts and none resolve my problem though I am now more
familiar with the wild goose population.
I thought that since I swapped out the connection string, maybe $result
was made null so I re-set it to the original connString and it still
didn't find auth_email in $results in the same database where it certainly
should have done.
Further, I've swapped out connStrings before with positive results, so...
hmmm...
My goal, when working, is to echo the Recordset2 into a form with a
do/while loop that will permit me to update their record in the 2nd db.
Since the var_dump is 0, obviously this below isn't giving me a list of
authors in the second table whose email addresses appear in the $results
array, but I include it as example of what I want use to start the form in
the page.
do {
$row_Recordset2['auth_email_addr '];
} while($row_Recordset2 = mysql_fetch_assoc($Recordset2));
As always, any pointer you can give are appreciated and correct answers
are Accepted.
Thank you.

No comments:

Post a Comment