I am trying to rewrite a piece of code that used several mysql_query calls to use one mysqli_... but cannot get it to work. If I simply replace my mysql_query statements with mysqli_query statements in the same place I get "Commands out of sync; you can't run this command now"
If I instead try to pull all the queries into a mysqli_multi_query I get a "Notice: Undefined variable: activeUser in /home/almostes/public_html/addrUpdate-proc-multi.php on line 14" error.
In a nutshell this is what I had
// get list of all active users
SELECT entity_id FROM customer_entity_int WHERE attribute_id = 153 and value = 1 ORDER BY entity_id
// cycle through this list of entity_ids checking is there an address stored against this user
SELECT * FROM customer_address_entity WHERE parent_id = $entity_id;
// if no address stored against this user get the info stored in customer_entity_varchar
SELECT * FROM customer_entity_varchar WHERE entity_id = $entity_id;
// and then enter this into the appropriate address tables
INSERT INTO customer_address_entity VALUES (blah, blah, blah);
I think I need to replace this with something like
$query = "SELECT entity_id FROM customer_entity_int WHERE attribute_id = 153 and value = 1 ORDER BY entity_id;"; # get list of all active users#
$query .= "SELECT * FROM customer_address_entity WHERE parent_id = $entity_id;"; # is there an address stored against this name
$query .= "SELECT * FROM customer_entity_varchar WHERE entity_id = $entity_id;"; # get the info stored in customer_entity_varchar
$query .= "INSERT INTO customer_address_entity VALUES (blah, blah, blah);"
$result = mysqli_multi_query($mysqli, $query);
/* execute multi query */
if ($result) {
do {
/* store first result set */
if ($result = mysqli_store_result($mysqli)) {
while ($row = mysqli_fetch_assoc($result)) {
$entity_id = $row['entity_id'];
echo "<br />active user = $entity_id<br />";
}
mysqli_free_result($result);
}
/* print divider */
if (mysqli_more_results($mysqli)) {
printf("-----------------\n");
}
if (($result = mysqli_num_rows($mysqli)) < 1) // if no address stored against this user retrieve the registration data and enter into address data fields
{
echo '<br />yes<br />';
}
} while(mysqli_more_results($mysqli) && mysqli_next_result($mysqli));
}
But a) this gives a "Notice: Undefined variable: activeUser in /home/almostes/public_html/addrUpdate-proc-multi.php on line 14" error where line 14 is "$query .= "SELECT * FROM customer_address_entity WHERE parent_id = $entity_id;";"
and then gives the echoed output
"active user = 5
active user = 6
active user = 78"
and b) I cannot see the syntax to move through the different sql queries to get the users without address info and the retrieve the desired fields
Any help would be much appreciated. Many thanks