0

This is an odd question, as it's something I've done countless times in the past. I'm simply running a query and returning a single result using fetchOne(), and then using the result in a new query. The issue here is that the query isn't reading the result, despite the result being there.

The two queries:

$current_order_query = "SELECT billing_name FROM $table WHERE customer_id = 7324 ORDER BY increment_id DESC LIMIT 1";
$current_billing_name = $readConnection->fetchOne($current_order_query);

$second_query = "SELECT billing_name FROM $table2 WHERE billing_name LIKE '$current_billing_name'";
$second_billing_name = $readConnection->fetchOne($second_query);

What's confusing me, even more, is that I can simply echo the $current_billing_name and it returns the result just fine as a string. I tried manually entering a string into the second query to see if it was that, but the query worked then. The first query is indeed returning the result correctly, but the second query is simply not taking it.

(The purpose of the queries is to find the billing name of the current order, and then run a check for matches in a custom blacklist)

Hopefully, someone can spot something I'm completely overlooking before I pull the rest of my hair out.

EDIT:

if(!$second_billing_name){
    // Nothing found, continue to next thing
} else {
    // Billing name found in the blacklist, email admin
}
  • What are table variables? – Dominic Xigen Jun 26 at 22:57
  • $table = $resource->getTableName('sales_flat_order_grid'); $table2 = $resource->getTableName('blacklist'); – taskle Jun 26 at 22:58
  • Have you considered using a join to link two tables together and do as single query? – Dominic Xigen Jun 26 at 23:12
  • I've considered it, but haven't really thought it out since the tables have no common column except for the billing_name which may not even have a matching key. Could you give an example? I've updated the OP with what I'm doing after this query. – taskle Jun 26 at 23:36
  • 1
    I was maybe thinking something like this stackoverflow.com/a/10022406/10121426 – Dominic Xigen Jun 26 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.