foreach遍历后的二维数组[0]=>和[name]=>显示的一样?

显示结果为
Array
(
    [0] => 6f79c73926857938c9f4b742c46b1a09.jpg
    [path] => 6f79c73926857938c9f4b742c46b1a09.jpg
)
正常的不应该是
Array
(
    [0] => array
    [path] => 6f79c73926857938c9f4b742c46b1a09.jpg
)
吗?
下面上代码,这几段代码的功能是显示商品列表信息,点击详情显示更多信息包括上传的图片(代码有点长)
显示列表代码
<?php 
include "../../conf/configandconn.php";
require_once '../../comm/comm.func.php';
$sql="SELECT p.cid,p.date,p.product_id,p.product_content,p.product_level,p.product_name,p.product_price,p.status,c.catalog_name,c.id FROM product AS p JOIN catalog c ON p.cid=c.id";
$totalrows=getresultnum($sql);
$pagesize=2;
$totalpage=ceil($totalrows/$pagesize);
$page = isset($_REQUEST['page'])?(int)$_REQUEST['page']:1;
if($page<1||$page==null||!is_numeric($page)){
$page=1;
}
if($page>=$totalpage)$page=$totalpage;
$offset=($page-1)*$pagesize;
$sql="SELECT p.cid,p.date,p.product_id,p.product_content,p.product_level,p.product_name,p.product_price,p.status,c.catalog_name,c.id FROM product AS p JOIN catalog c ON p.cid=c.id LIMIT {$offset},{$pagesize}";
$res=mysql_query($sql);
if($res&&mysql_num_rows($res)){
while($row =mysql_fetch_assoc($res)){
$data[] = $row;
}
}else{
$data = array();
}
/* print_r($data);
exit; */
function showpage($page,$totalpage,$sep="&nbsp;"){
$p="";
$url = $_SERVER ['PHP_SELF'];
$index = ($page == 1) ? "首页" : "<a href='{$url}?page=1'>首页</a>";
$last = ($page == $totalpage) ? "尾页" : "<a href='{$url}?page={$totalpage}'>尾页</a>";
$prev = ($page == 1) ? "上一页" : "<a href='{$url}?page=".($page-1)."'>上一页</a>";
$next = ($page == $totalpage) ? "下一页" : "<a href='{$url}?page=".($page+1)."'>下一页</a>";
$str = "总共{$totalpage}页/当前是第{$page}页";
for($i=1;$i<=$totalpage;$i++){
if($page==$i){
$p.="[{$i}]";
}else{
$p.="<a href='{$url}?page={$i}'>[{$i}]</a>";
}
}
 $pagestr=$str.$sep.$index.$sep.$prev.$sep.$p.$sep.$next.$sep.$last;
 return $pagestr;
}
?>
<html>
<head>
<meta charset="utf-8">
<title>-.-</title>
<link rel="stylesheet" href="../../css/backstage.css">
<link rel="stylesheet" href="../../css/jquery-ui-1.10.4.custom.css" />
<script src="../../js/jquery-1.10.2.js"></script>
<script src="../../js/jquery-ui-1.10.4.custom.js"></script>
<script src="../../js/jquery-ui-1.10.4.custom.min.js"></script>
</head>

<body>
<div id="showDetail"  style="display:none;">

</div>
<div class="details">
                    <div class="details_operation clearfix">
                        <div class="bui_select">
                            <input type="button" value="添&nbsp;&nbsp;加" class="add" οnclick="addPro()">
                        </div>
                        <div class="fr">
                            <div class="text">
                                <span>商品名称:</span>
                                <div class="bui_select">
                                    <select name="" id="" class="select">
                                        <option value="1">测试内容</option>
                                        <option value="1">测试内容</option>
                                        <option value="1">测试内容</option>
                                    </select>
                                </div>
                            </div>
                            <div class="text">
                                <span>上架时间:</span>
                                <div class="bui_select">
                                    <select name="" id="" class="select">
                                        <option value="1">测试内容</option>
                                        <option value="1">测试内容</option>
                                        <option value="1">测试内容</option>
                                    </select>
                                </div>
                            </div>
                            <div class="text">
                                <span>搜索</span>
                                <input type="text" value="" class="search">
                            </div>
                        </div>
                    </div>
                    <!--表格-->
                    <table class="table" cellspacing="0" cellpadding="0">
                        <thead>
                            <tr>
                                <th width="10%">编号</th>
                                <th width="20%">商品名称</th>
                                <th width="20%">商品分类</th>
                                <th width="20%">是否上架</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php $i=1;foreach($data as $val): ?>
                            <tr>
                                <!--这里的id和for里面的c1 需要循环出来-->
                                <td><input type="checkbox" id="c1" class="check" value=<?php echo $val['product_id'];?>><label for="c1" class="label"><?php echo $i;?></label></td>
                                <td><?php echo $val['product_name']; ?></td>
                                <td><?php echo $val['catalog_name'];?></td>
                                <td>
                                <?php 
$show=($val['status']==1)?"上架":"下架";
echo $show;
                                ?>
                                </td>
                                <td align="center">
                                 <input type="button" value="详情" class="btn" οnclick="showDetail(<?php echo $val['product_id'];?>,'<?php echo $val['product_name'];?>')"><input type="button" value="修改" class="btn"><input type="button" value="删除" class="btn">
                            <div id="showDetail<?php echo $val['product_id'];?>" style="display:none;">
                         <table class="table" cellspacing="0" cellpadding="0">
                         <tr>
                         <td width="20%" align="right">商品名称</td>
                         <td><?php echo $val['product_name'];?></td>
                         </tr>
                         <tr>
                         <td width="20%"  align="right">商品类别</td>
                         <td><?php echo $val['catalog_name'];?></td>
                         </tr>
                         <tr>
                         <td width="20%"  align="right">商品货号</td>
                         <td><?php echo $val['product_id'];?></td>
                         </tr>
                         <tr>
                         <td width="20%"  align="right">商品数量</td>
                         <td><?php echo $row['pNum'];?></td>
                         </tr>
                         <tr>
                         <td  width="20%"  align="right">商品价格</td>
                         <td><?php echo $val['product_price'];?></td>
                         </tr>
                         <tr>
                         <td  width="20%"  align="right">幕课网价格</td>
                         <td><?php echo $row['iPrice'];?></td>
                         </tr>
                         <tr>
                         <td width="20%"  align="right">商品图片</td>
                         <td>
                         <?php 
                         $images=getallimgbyproid($val['product_id']);
print_r($images);
                         foreach($images as $img){
                         echo "<img src='../../img/upload/proimg/img/{$img['path']}' alt=''/>&nbsp;";
                         }
                         ?>
                         </td>
                         </tr>
                         <tr>
                         <td width="20%"  align="right">是否上架</td>
                         <td>
                         <?php 
                         $show=($row['isShow']==1)?"上架":"下架";
echo $show;
                         ?>
                         </td>
                         </tr>
                         <tr>
                         <td width="20%"  align="right">是否热卖</td>
                         <td>
                         <?php 
                         $hot=($row['isShow']==1)?"热卖":"促销";
echo $hot;
                         ?>
                         </td>
                         </tr>
                         </table>
                         <span style="display:block;width:80%; ">
                         商品描述<br/>
                         <?php echo $val['product_content'];?>
                         </span>
                        </div>                           
                                </td>
                            </tr>
                           <?php $i++; endforeach;?>
                           <td colspan="7"><?php echo showpage($page,$totalpage);?></td>
                        </tbody>
                    </table>
                </div>
<script type="text/javascript">
function showDetail(id,t){
$("#showDetail"+id).dialog({
  height:"auto",
      width: "auto",
      position: {my: "center", at: "center",  collision:"fit"},
      modal:false,//是否模式对话框
      draggable:true,//是否允许拖拽
      resizable:true,//是否允许拖动
      title:"商品名称:"+t,//对话框标题
      show:"slide",
      hide:"explode"
});
}
function addPro(){
window.location='addPro.php';
}
</script>
</body>
</html>
require_once '../../comm/comm.func.php';的内容为
[code=php]function getallimgbyproid($product_id){
$sql="select path from img where product_id={$product_id}";
$result = mysql_query($sql);
$arr=mysql_fetch_array($result);
return $arr;
}

结果的为

代码有点长,还望有经验的朋友指点一下。非常感谢!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值