2011-12-16 89 views
0

我只是一個新手。有人可以幫助我迭代或循環從我的表中輸入的所有文本中的計算輸出。輸出顯示但僅在一行中顯示,並且不顯示在表的另一行中。幫助我解決這個問題更值得讚賞。如何迭代或循環使用每個()在jQuery/javascript

<head> 
<script language="javascript" type="text/javascript"> 

function calculateSellingPrice() 
{ 
    var txtcost = document.getElementById("cost"); 
    var txtsellingprice = document.getElementById("sellingprice"); 
    var txtprofit = document.getElementById("profit"); 


    //find the total first 
    var total = parseFloat(txtcost.value) + parseFloat(txtpostage.value); 

    //for selling price computation 
    txtsellingprice.value = total; 

//for ebay fees computation 
if (txtsellingprice.value > 50){ 
    txtebayfees.value = parseFloat(txtsellingprice.value - 50) * 0.05 + 3.5; 
} 
else if (txtsellingprice.value <= 50){ 
txtebayfees.value = parseFloat(txtsellingprice.value) * 0.07; 
} 
} 
//--> 
</script> 

</head> 
<body onload="calculateSellingPrice();">  
<table> 
    <tr> 
    <td><center>SKU</center></td> 
    <td><center>Selling Price</center></td> 
    <td><center>Cost</center></td> 
    </tr>  
     <?php 
     $result = mysql_query("SELECT sku, sellingprice FROM tbl_inventory");        
     while ($myrow = mysql_fetch_row($result)) 
     { 
    ?> 
     <tr> 
    <td> 
     <?php echo "<input type='text' id='sku' name='sku' />"; ?> 
    </td> 
    <td> 
     <?php echo "<input type='text' id='sellingprice' name='sellingprice' />"; ?> 
    </td> 
    <td> 
     <?php echo "<input type='text' id='cost' name='cost' />"; ?> 
    </td> 
    </tr> 
    <?php> 
    } 
    ?> 
</table> 
+0

你問如何解決你的PHP模板文件,所以它會輸出到多行?或者你問如何做一些客戶端使用JavaScript?你的問題不清楚如書面。另外,如果你不問一個PHP問題,那麼請發佈瀏覽器看到的生成的javascript(你可以在瀏覽器中使用View/Source來捕獲它),這樣我們就可以看到瀏覽器實際看到的內容。 – jfriend00 2011-12-16 03:18:06

回答

0

只是指出一些問題,你是查詢你的表,你需要根據返回的值來計算,對吧?

也許你需要一個值來計算的東西..看到波紋管我是怎麼做..

<?php echo "<input type='text' id='sellingprice' name='sellingprice' value='".$myrow['sellingprice']."' />"; ?> 

你缺少這一部分 - >value='".$myrow['sellingprice']."'

0

首先:不要寫螺栓請。

第二:如果您需要表格,請使用jQuery Plugin Datatables.net。太棒了!

只需創建一個數字數組,看起來像這樣在PHP:

$x = array(0 => array(
      0 => 'this is a name', 
      1 => 'this is a price', 
      2 => 'this is a x') 
     0 => array(
      0 => 'this is a name', 
      1 => 'this is a price', 
      2 => 'this is a x') 
); 

然後做json_encode(array('aaDara => $x));

而且使用它作爲一個AjaxSource。這太好了!