doudai8083 2014-09-04 06:03
浏览 43

在数组循环中显示数组

I am working on a project where in I have tables of Invoices, Quotations and many more.

Where I am stuck is here -

I am saving values of quotation in to a table as a n array. Eg :-

If two services are selected then it saves it in this way : Service1, service2 Similarly its quantity and charges are saved in d same way:

 Sqty : 1,1
 Scharge: 100,300

Now For Invoice, I get the quotation id and service name from POST

$qdetails = mysql_query("SELECT * FROM tbl_quotation WHERE id ='$qid';") 
 or die(mysql_error()); 
  $qdet = mysql_fetch_array( $qdetails );
  $pcharge = $qdet['pcharge'];
  $scharge = $qdet['scharge'];
  $pqty = $qdet['pqty'];
  $sqty = $qdet['sqty'];

Then display the output in the following table - tbl_service_info is my table which has all the details of the service

<?php

foreach ($_POST['service'] as $key => $value) {


$query=("select * from tbl_service_info WHERE sname = '$value'");

$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );

while($row=mysql_fetch_array($result)){
$product = @$row["sname"];
$prid = @$row["id"];
$sdetails = @$row["details"];
  ?> 
      <tr class="item-row">
          <td class="item-name"><div class="delete-wpr">
<textarea name="services[]"><?php echo $value ; ?></textarea></div></td>
          <td class="description"><textarea><?php echo $sdetails; ?></textarea></td>
          <td><textarea class="description"><?php echo $sunit; ?></textarea></td>
               <?php    } 
 $scharge1 = explode(",",$scharge);
foreach ($scharge1 as $keysc => $valuesc) {   ?>


          <td><textarea class="cost" name="scharge[]"> <?php     
 echo $valuesc;?> </textarea>  </td> <?php } ?>




 <?php     
 $sqty1 = explode(",",$sqty);

foreach ($sqty1 as $key2 => $value2) { ?>
          <td><textarea class="qty" name="snos[]"><?php echo $value2;?></textarea></td>
<?php } ?>

          <td><span class="price"></span></td>
      </tr>

       <?php } ?>

This is what i get.

http://oi61.tinypic.com/286v30j.jpg

http://oi61.tinypic.com/286v30j.jpg

The Unit Cost and Nos are not looping with the main loop.

Please help. Also correct my question If I have written it the wrong way.

Thanks...

  • 写回答

1条回答 默认 最新

  • duanjuebin2519 2014-09-04 06:33
    关注

    Following my comment, here is the workaround that should work in your case.

    You can use a temporary value to echo the correct part of the exploded string ($charge)

    $i = 0;
    while($row=mysql_fetch_array($result)){
    
    // Rest of your code
    
        $scharge1 = explode(",",$scharge);
        // Remove that foreach ($scharge1 as $keysc => $valuesc) {   ?> 
        <td><textarea class="cost" name="scharge[]"> 
          <?php echo $scharge1[$i];?>
        </textarea></td> 
    
    // Rest of your code, also change the NOS part
    
        // Before the very end of your while loop, increment $i
        ++$i;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测