0

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();
 }
4

1 回答 1

0

这是由于mysql_query在循环另一个调用的结果时调用获取数据引起的。

目前,您正在呼吁getLocation每一个结果。因此,如果您有 10 个结果,您将对数据库进行 10 次调用,这些调用都将返回相同的内容。

相反,将getLocation调用更改为返回一个字符串并在循环之前调用它:

$location = getLocation();

然后在循环中你可以这样做:

<?php echo $location ?>
于 2013-07-09T13:15:12.670 回答