2013-07-09 12:55 阅读 46

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)) {**
            <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>
                <div class="tab-content">
                    <div class="tab-pane active" id="tab1">
                        <form class="form-horizontal">
                            <p>Asset General Information. Some order goes here.</p>
                                <!-- 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-->**

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>";
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanjia2415 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 ?>
    点赞 评论 复制链接分享