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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改