doutizha7526 2012-03-21 04:11
浏览 40
已采纳

joomla-php mysql没有使用先前查询中的数据更新记录

I'm counting the right answers field of a table and saving that calculated value on another table. For this I'm using two queryes, first one is the count query, i retrieve the value using loadResult(). After that i'm updating another table with this value and the date/time. The problem is that in some cases the calculated value is not being saved, only the date/time.

queries look something like this:

        $sql = 'SELECT count(answer)

                FROM #_questionsTable
                WHERE 

                    answer = 1

                    AND

                    testId = '.$examId;

        $db->setQuery($sql);

        $rightAnsCount = $db->loadResult();

        $sql = 'UPDATE #__testsTable

                SET finish = "'.date('Y-m-d H:i:s').'", rightAns='.$rightAnsCount.'

                WHERE testId = '.$examId;

        $db->setQuery($sql);

        $db->Query();

answer = 1 means that the question was answered ok.

I think that when the 2nd query is executed the first one has not finished yet, but everywhere i read says that it waits that the first query is finished to go to the 2nd, and i don't know how to make the 2nd query wait for the 1st one to end.

Any help will be appreciated. Thanks!

  • 写回答

3条回答 默认 最新

  • duanhuan6336 2012-03-21 04:59
    关注
    1. a PHP MySQL query is synchronous ie. it completes before returning - Joomla!'s database class doesn't implement any sort of asynchronous or call-back functionality.

    2. While you are missing a ';' that wouldn't account for it working some of the time.

    3. How is the rightAns column defined - eg. what happens when your $rightAnsCount is 0

    4. Turn on Joomla!'s debug mode and check the SQL that's generated in out the profile section, it looks something like this

    eg.

    Profile Information
    
    Application afterLoad: 0.002 seconds, 1.20 MB
    Application afterInitialise: 0.078 seconds, 6.59 MB
    Application afterRoute: 0.079 seconds, 6.70 MB
    Application afterDispatch: 0.213 seconds, 7.87 MB
    Application afterRender: 0.220 seconds, 8.07 MB
    Memory Usage
    
    8511696
    8 queries logged.
    
    SELECT * 
          FROM jos_session 
          WHERE session_id = '5cs53hoh2hqi9ccq69brditmm7'
    DELETE 
          FROM jos_session 
          WHERE ( TIME < '1332089642' )
    etc...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)