1

I’m doing a function that after the user saves the product it updates or inserts the product in a table, but to know if magento has to update or insert I have to verify if the product is in the table, when I do the select query I’m obtaining nothing in my variables

Here’s my code

            $resource = Mage::getSingleton('core/resource');
            $readConnection = $resource->getConnection('core_read');

            $tabla = $resource->getTableName('_destacados_web');

            $querySelect = "SELECT DCOD, DCATEGORIA FROM ".$tabla." WHERE DMARCA = '".$partesSku[0]."' AND DITEM = '".$partesSku[1]."'";

            $results = $readConnection->fetchAll($querySelect);

            $codigo = $results['DCOD'];
            $categoria= $results['DCATEGORIA '];

As you can see, the idea it’s really simple, just obtaining two rows of my table and saving that into the variables, but every time I run the code I get nothing in the variables,

I hope you guys can help me! Thanks

  • you can just skip the verification and do an INSERT..ON DUPLICATE KEY UPDATE... Just make sure you set a unique key on the DMARCA and DITEM columns. – Marius Jul 8 '14 at 19:01
2

We could definitely use more information, but for start, $readConnection->fetchAll($querySelect) returns an array where each record is one row, so if you want the first record you could do something like:

$codigo = $results[0]['DCOD']; $categoria= $results[0]['DCATEGORIA '];

  • Thanks!! that's why it was not working! thanks a lot! – dzuritaa Jul 8 '14 at 20:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.