Php 我试图显示单行值,但它显示多个值

Php 我试图显示单行值,但它显示多个值,php,Php,当我试图使用explode从数据库中检索值时,但当我使用foreach循环时,它并没有得到正确的结果。每行显示多个时间。所以请解决我的问题 index.php <?php require_once('DB.class.php'); $db = new DB(); $db->connect(); ?> <HTML> <HEAD> <TITLE>PHP jQuery Dynamic Textbox</TITLE> <LIN

当我试图使用explode从数据库中检索值时,但当我使用foreach循环时,它并没有得到正确的结果。每行显示多个时间。所以请解决我的问题

index.php

<?php
require_once('DB.class.php'); 

$db = new DB();
$db->connect();
?>

<HTML>
<HEAD>
<TITLE>PHP jQuery Dynamic Textbox</TITLE>
<LINK href="style.css" rel="stylesheet" type="text/css" />


</HEAD>
<BODY>
<FORM name="frmProduct" method="post" action="">
<div id="output1">
<legend>Product List</legend>
<table width="90%" align="center" class="table table-bordered table-hover">
<tr>
<th>item Name</th>
<th>item Price</th>
<th>Qty</th>
<th>Unit</th>

</tr>
<?php
$total=0;

$templist=$db->SelectTable("item","","");
if(count($templist)>0) {
foreach($templist as $row_temp)
{ 
?>  
<tr>

<?php 

$qty=$row_temp['qty'];
$qt=@explode(',',$qty);
$un=$row_temp['unit'];
$unit=@explode(',',$un);
foreach($qt as $q => $value){
foreach($unit as $uni => $value1){ 

?>
<td class="righr"><?=$row_temp['item_name'];?></td>
<td class="right"><?=$row_temp['item_price'];?></td>
<td class="right"><?=$value?></td>
<td class="right"><?=$value1?></td>

<td align="center"><input type="button" name="Delete" Value="Delete" onclick="showtempdata(<?=$row_temp['temp_id']?>);" class="btn btn-danger" /></td>
</tr>
<?php
}
}
//$mask=$mask[1];
}
?>

<?php
}else{
?>  <tr><td colspan="10"><label class="text-error" style="text-align:center"> Product Not added</label></td></tr>
<?php }?>
</table>
</form>
</BODY>
</HTML>
试试这个

 <?php
require_once('DB.class.php'); 

$db = new DB();
$db->connect();
?>

<HTML>
<HEAD>
<TITLE>PHP jQuery Dynamic Textbox</TITLE>
<LINK href="style.css" rel="stylesheet" type="text/css" />


</HEAD>
<BODY>
<FORM name="frmProduct" method="post" action="">
<div id="output1">
<legend>Product List</legend>
<table width="90%" align="center" class="table table-bordered table-hover">
<tr>
<th>item Name</th>
<th>item Price</th>
<th>Qty</th>
<th>Unit</th>

</tr>
<?php
$total=0;

$templist=$db->SelectTable("item","","");
if(count($templist)>0) {
foreach($templist as $row_temp)
{ 
?>  
<tr>

<?php 

$qty=$row_temp['qty'];
$qt=@explode(',',$qty);
$un=$row_temp['unit'];
$unit=@explode(',',$un); ?>
<td class="righr"><?=$row_temp['item_name'];?></td>
<td class="right"><?=$row_temp['item_price'];?></td>
<td class="right"><?php foreach($qt as $q => $value){?><?=$value?><?php }?></td>
<td class="right"><?php  foreach($unit as $uni => $value1){?><?=$value1?><?php }?></td>

<td align="center"><input type="button" name="Delete" Value="Delete" onclick="showtempdata(<?=$row_temp['temp_id']?>);" class="btn btn-danger" /></td>
</tr>

<?php
 }
}else{
?>  <tr><td colspan="10"><label class="text-error" style="text-align:center"> Product Not added</label></td></tr>
<?php }?>
</table>
</form>
</BODY>
</HTML>

您好,您将得到相同的行,但每行$unit将不同。为了让这变得容易,你能发布你现在得到的输出和预期输出吗?谢谢,但它只显示在同一行中,我想要打断数量和单位,并显示在下一行中,如hi在一行中,其值21和单位4在下一行5中,依此类推。我想请你简要解释一下,或者给我举例说明它应该如何在表格中显示表格?如项目名称项目价格单位数量您好21 11 2 12 3 13如是我想要我的结果
CREATE TABLE IF NOT EXISTS `item` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `item_name` varchar(255) NOT NULL,
  `item_price` int(11) NOT NULL,
  `unit` varchar(11) NOT NULL,
  `qty` varchar(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

INSERT INTO `item` (`id`, `item_name`, `item_price`, `unit`, `qty`) VALUES
(1, 'hello', 21, '1,2,3', '11,12,13'),
(2, 'hi', 22, '4,5,6', '67,8'),
(3, 'test', 344, '0', ''),
(4, 'wow', 444, '0', '');
 <?php
require_once('DB.class.php'); 

$db = new DB();
$db->connect();
?>

<HTML>
<HEAD>
<TITLE>PHP jQuery Dynamic Textbox</TITLE>
<LINK href="style.css" rel="stylesheet" type="text/css" />


</HEAD>
<BODY>
<FORM name="frmProduct" method="post" action="">
<div id="output1">
<legend>Product List</legend>
<table width="90%" align="center" class="table table-bordered table-hover">
<tr>
<th>item Name</th>
<th>item Price</th>
<th>Qty</th>
<th>Unit</th>

</tr>
<?php
$total=0;

$templist=$db->SelectTable("item","","");
if(count($templist)>0) {
foreach($templist as $row_temp)
{ 
?>  
<tr>

<?php 

$qty=$row_temp['qty'];
$qt=@explode(',',$qty);
$un=$row_temp['unit'];
$unit=@explode(',',$un); ?>
<td class="righr"><?=$row_temp['item_name'];?></td>
<td class="right"><?=$row_temp['item_price'];?></td>
<td class="right"><?php foreach($qt as $q => $value){?><?=$value?><?php }?></td>
<td class="right"><?php  foreach($unit as $uni => $value1){?><?=$value1?><?php }?></td>

<td align="center"><input type="button" name="Delete" Value="Delete" onclick="showtempdata(<?=$row_temp['temp_id']?>);" class="btn btn-danger" /></td>
</tr>

<?php
 }
}else{
?>  <tr><td colspan="10"><label class="text-error" style="text-align:center"> Product Not added</label></td></tr>
<?php }?>
</table>
</form>
</BODY>
</HTML>