English 中文(简体)
页: 1 只有在最后一行才有工作
原标题:jQuery looping only works on last row

我正试图在MySQL的表格中逐字逐字显示投标项目的状况,不过,表格最后一行只收回结果。

<?php

$query = "SELECT item, description, price, imageData, status, username, item_id FROM items"; 
$result = mysql_query($query) or die(mysql_error());

$z=0;
while($row = mysql_fetch_array($result))
{   
    //echo other columns here//
    echo "<td><div id=status$z></div></td>";

    ?>

    <script type=text/javascript>
        function updatestatus(itemnum)
        {
            var url="updatestatus.php?auc=<?php echo $row[ item_id ]; ?>";
            jQuery( #status  + itemnum).load(url);  
        }

        setInterval("updatestatus(<? echo $z?>)", 1000);
    </script>

    <?   

    $z++;

}

?>

当我从浏览器中看到来源时,每个浏览器的数值是正确的。 我在这里失踪了什么?

这里是《最新状况法》。 php

<?php

    session_start();
    require_once("connect.php");

    $id = $_GET[ auc ];
    $getstatus = mysql_query("SELECT status FROM items WHERE item_id =  $id   ");
    $row = mysql_fetch_array($getstatus);

    echo"$row[status]";

?>
最佳回答

一切都看好,除非它认为你会重复多处提及你的<条码>最新情况(功能。

在 Java稿中,如果你以相同的名称设立多种职能,则称这些职能只能产生其中一种职能,通常是第一个或最后一个职能(取决于执行),那么,你在这些职能中操作的所有守则都需要坐在one<>>>>>>职能机构。

如果你重新决心使用你制定的守则,那么你需要将所有更新的电话输入一个职能机构。 找到更好的办法满足你们的需要,但按照你制定的法典行事,这或许会更好:

<?php

    $query = "SELECT item, description, price, imageData, status, username, item_id FROM items";
    $result = mysql_query($query) or die(mysql_error());

    $javascript = "";
    $z=0;

    while($row = mysql_fetch_array($result))
    {

        //echo other columns here//
        echo "<td><div id=status$z></div></td>";

        // build the javascript to be put in the function later over here...
        $javascript .= "jQuery( #status". $z ." ).load( updatestatus.php?auc=". $row[ item_id ] ." );";

        $z++;

    }

?>

...and then further down the page, create the javascript (modified slightly):

<script type=text/javascript>

    function updatestatus()
    {
        <?php echo $javascript; ?>
    }

    setInterval(updatestatus, 1000);

</script>

因此,你基本上重新建立 Java,你需要你履行职务,在职能机构内部也这样做,然后确定间隔将意味着所有这些代码,在这种情况下,每二次。

和我一样,显然有更有效的方法实现你重新努力要做的工作,但现在这项工作应该很出色。 我希望这一点是有意义的,但请让我知道,你们是否需要澄清任何事情!

问题回答

I don t see that you re populating data using a incrementor. Is this supposed to be adding content to a page or replacing the content? from what it looks like it will just display one item, and then replace that one item with the next until it s done, which is why you see only the last row.

......

the jquery update isn t being fed the $i variable .. change the function to

职能更新(项目南){

and then jquery echo to jQuery( #status + itemnum).load(url);

then you can add the on-click/ or whatever to include the number onclick= updatestatus("1")

另一方面,你可能需要将项目总数转至这一职能,然后才能使项目周期顺畅(没有经过测试,但获得希望的想法)。

 function updatestatus(numitems) {
    var url = "";
    var itemID = "";
    for (i = 1; i <= numitems; i++) {
        itemid = getElementById( #status +numitems).getAttribute("itemID")
        url="updatestatus.php?auc="+itemID;
        jQuery( #status +numitems).load(url);    
    }
 }

setInterval("updatestatus()", 1000);

and the html element for "#status1" as created by the PHP should look like this:

<div id="status1" itemid="23455">
</div>




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...