0

I have some code to update a table:

$updateLastAttempt = new stdClass();
$tempDate = new DateTime('now');
$formattedDate = $tempDate->format('Y-m-d H:i:s');
$updateLastAttempt->id = $pxobjUpdate->id;
$updateLastAttempt->last_attempted_sms = "" . $formattedDate . "";
array_push($uniqueIdArray,$pxuniqueid);
array_push($recallRecordIdArray,$recallRecordid);

if ($debug != 1) {
    echo"<br>Update last attempt date to:".$formattedDate." for id:".$pxuniqueid. " recall Record id:".$recallRecordid;
    $db = JFactory::getDbo();

    $query = $db->getQuery(true);

    $fields = array(
        $db->quoteName('last_attempted_sms') . ' = "' . $formattedDate.'"',
    );

    $conditions = array(
        $db->quoteName('id') . ' = "'.$pxobjUpdate->id.'"',
    );

    $query->update($db->quoteName('#__patientrecalls_px_record'))->set($fields)->where($conditions);

    $db->setQuery($query);

    $result = $db->execute();
}

Originally I used an object and did an update that way but I was getting errors so I switched to this proceedural method. It's a joomla 3 site (I know it should be updated).

The problem I'm having is that not all of the records are updating. It seems to just ignore the update for a random number of records. It updates most of them but not all of them and I can't see anything that might cause this. It's just a straight up record update by using the id .

any ideas??

4
  • If the process is only working sometimes, then you don't have a coding problem, you have a data problem. We cannot help you without better debilugging details. Perhaps try to implement the Debugging techniques at Correct ways to verify update query is successful under conditions then edit your question to clarify the problem. Commented May 21 at 22:13
  • What kind of insights can you derive from this script? 3v4l.org/EcbLf Commented May 21 at 22:38
  • 1
    Put a try...catch around the $db->execute() and see if the query is failing for the records that don't get updated (use $query->dump() to get the full query string). If not then it must be that whatever you are using above this to select the $pxobjUpdate objects is missing some. Not sure what all of the stuff at the top before the if (debug) is doing for you. Is this all in a loop iterating over the $pxobjUpdate objects or a function that is passed a single $pxobjUpdate object to update?
    – RogerCO
    Commented May 23 at 20:55
  • My guess that the ID ($pxobjUpdate->id) is sometimes passed as empty (which could mean that the object in itself is empty). In addition, by quickly glancing at your code, I see that you have about 3 variables storing the ID, which is not good practice. One other reason is that the code might be failing at one point.
    – itoctopus
    Commented Jun 7 at 9:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.