php - 在数组循环内显示数组

标签 php mysql arrays loops

我正在从事一个项目,其中包含发票、报价单等表格。

我被困在这里 -

我将报价的值作为 n 数组保存到表中。例如:-

如果选择了两个服务,那么它会以这种方式保存:Service1, service2 同样它的数量和费用以同样的方式保存在d中:

 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 } ?>

这就是我得到的。

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

Unit Cost 和 Nos 不与主循环一起循环。

请帮忙。 如果我写错了,也请更正我的问题。

谢谢...

最佳答案

根据我的评论,这里是适用于您的情况的解决方法。

您可以使用临时值来回显分解字符串的正确部分($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;
}

关于php - 在数组循环内显示数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25658282/

相关文章:

mysql - 从表中删除重复行

C++ Ifstream 转换为类对象数组

python - Raspbian 上的 MySQL+Python 产生语法错误

php - 多个mysql查询多个文件上传

c++ - 为什么不能将 *pointer+offset 用作左值? ("error: non-lvalue in assignment")

java - 结果集到二维数组

php - 使用图标标志从数据库中设置选定值 select2

php - 如何在 ng-repeat 中使用 ng-class 为每个迭代 div 设置类

php - 使用来自 mysql 的信息从 PHP 打开 fancyBox

php - 投票系统多个答案