doue2666 2013-07-09 12:55
浏览 51
已采纳

MySQL Throwing无法执行查询。 命令不同步

i have some problem. My mysql is throwing some error :

Could not execute query.Commands out of sync; you can't run this command now

I have learn that the syntax itself perhaps conflict with the other function.

My case is, i have a page that getting result from database. And using while statement, it shows in the text box. Now, i want to update the values in the same page. Because some values are not text input, so it's not easy to get the values. I place another php function() inside the while() function.

here's the syntax:

while statement for rendering the textbox

     include '../functions/configuration.php';
        $query = "call sp_callViewTransc($ids)";
        $result = mysql_query($query) or die("Could not execute query. " . mysql_error());
        **while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {**
        **<!-- WHILE FUNCTION IS GETTING RESULT FROM DB -->**
            ?>
            <div class="tabbable"> <!-- Only required for left/right tabs -->
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tab1" data-toggle="tab">General Information</a></li>
                    <li><a href="#tab2" data-toggle="tab">Computer Information</a></li>
                    <li><a href="#tab3" data-toggle="tab">OS and Licenses</a></li>
                    <li><a href="#tab4" data-toggle="tab">Remarks</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="tab1">
                        <form class="form-horizontal">
                            <p>Asset General Information. Some order goes here.</p>
                            <fieldset>
                                <!-- Text input-->
                                <div class="control-group">
                                    <label class="control-label">Location</label>
                                    <div class="controls">
                                        <input id="idms_location" name="idms_location" type="text" placeholder="location" class="input-xlarge" readonly="readonly" value="<?php echo $row['idms_location']; ?>">
                                        <?php getLocation(); ?>
                                        **<!-- getLocation() function is another function in another file that getting dropdown values-->**
                                    </div>
                                </div>

Is there any php function to solve this code?

** update **

here's my second function in php that getting results for combobox

   function getLocation() {
     $query_location = "SELECT location, idms_location FROM ms_location";
     $location_list = mysql_query($query_location) or die("Could not execute query." .     mysql_error());
     echo "<select>";
       while ($row = mysql_fetch_array($location_list, MYSQL_ASSOC)) {
     echo("<option value='" . $row['idms_location'] . "'>" . $row['location'] . " </option>");
   }
     echo "</select>";
     mysql_close();
 }
  • 写回答

1条回答 默认 最新

  • duanjia2415 2013-07-09 13:15
    关注

    This is caused by calling mysql_query to get data while you're looping over the results from another call.

    At the moment you are calling getLocation for every result. So if you have 10 results you are making 10 calls to the database which will all return the same thing.

    Instead, change the getLocation call to return a string and call it before the loop:

    $location = getLocation();
    

    Then in the loop you can do:

    <?php echo $location ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!