2017-01-09 82 views
0
function view_amshops_order_details() 
{ 
    session_start(); 
    if($_SESSION['UserId']<=0) 
    { 
    signin(); 
    } 

    //here fetch your signup form for session// 

    $rs2=mysql_query("select *from user where u_id='$_SESSION[UserId]'"); 
    $data2=mysql_fetch_assoc($rs2); 
    $smarty=new smarty(); 
    $smarty->assign($data2); 

    global $View_Path; 
    $i=0; 
    $amshops=mysql_query("select * from payment_amshops join order_amshops on payment_om_id=om_id join delivery_address on om_dl_id=dl_id join payment_status on payment_status_id = status_id WHERE payment_om_id=om_id AND payment_u_id='$_SESSION[UserId]'"); 

    $records=array(); 
    $smarty->assign(array("act"=>"view_amshops_order_details")); 
    while($detail=mysql_fetch_assoc($amshops)) 
    { 

     $order_number=$detail['om_order_number']; 
     $detail['size']=strlen($i); 
     array_push($records,$detail); 
     //$inner_records=array(); 
     $inner_amshops=mysql_query("select * from addtocart_2 join category2 on cart_cg_id=cg_id where cart_cg_id=cg_id AND order_number='$order_number'"); 
     while($inner_detail=mysql_fetch_assoc($inner_amshops)) 
     { 
      if($inner_detail[cg_pic]!='')$file=$View_Path.$inner_detail[cg_pic]; 
      if(!file_exists($Upload_Path.$inner_detail[cg_pic]))$file=''; 

      array_push($records[$i],$inner_detail); 

     } 
     //$detail['size']=$i+1; 
     //array_push($records[0],$i); 

     $i++; 

    } 
// echo "<pre>"; 
// print_r($records); 
// exit; 

    $smarty->assign(array("records"=>$records, "file"=>$file)); 
    $smarty->display("templates/view_amshops_order_details_2.tpl"); 
} 




and my tpl file 

{foreach $records as $detail} 
    <table class="table table-responsive" style="border:solid #BBBBBB 1px;"> 


    <thead> 
    <tr bgcolor="#E8E8E8"> 
    <td colspan="4" align="left" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <a href="#" class="btn btn-primary">OrderID -&nbsp;{$detail.om_order_number}</a></td> 
    <td colspan="4" align="center">&nbsp; 
    <a href="#" class="btn btn-success"><b>&nbsp;&nbsp;Payment&nbsp;-&nbsp;{$detail.status_name}&nbsp;&nbsp;</b></a> 
    </td> 
    </tr> 
    </thead> 

    {for $i=0 to $detail['size']} 
    {if $detail[$i].order_number} 
    <tbody> 
    <tr > 

    <td><br /> 
    <a href="index.php?act=bigview_men_cloth&cg_id={urlencode(base64_encode($detail[$i].cg_id))}"> 
    <img src="admin_panel/images/category/{$detail[$i].cg_pic}" class="img-thumbnail" style="width:50px;; height:70px;"/> 
    </a> 
    </td> 

    <td align="left"><br /> 
    {$detail[$i].cg_name}&nbsp;{$detail[$i].cg_type}<br /> 
    {if $detail[$i].cart_size}Size:&nbsp;{$detail[$i].cart_size}{else}{/if} 
    <br /> 
    Seller:&nbsp;{$detail[$i].cg_seller} 
    </td> 
    <td align="left"><br />&nbsp;{$detail[$i].cart_size}</td> 
    <td align="left"><br />Rs.&nbsp;{$detail[$i].cart_total}</td> 
    <td align="left"><br />&nbsp;{$detail[$i].cg_dldetail}</td> 
    <td align="left"><br />&nbsp;</b><br /><br /><br /><br /></td> 
    </tr> 
    </tbody> 
    {/if} 
    {/for} 

    <thead> 
    <tr bgcolor="#F5F5F5"> 
    <td colspan="4" align="left" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    </td> 
    <td colspan="4">&nbsp; 
    <a href="#" class="btn btn-danger"><b>&nbsp;&nbsp;Order Total&nbsp;:&nbsp;Rs.&nbsp;{$detail.om_price}&nbsp;&nbsp;</b></a> 
    </td> 
    </tr> 
    </thead> 

    </table> 
    {/foreach} 

我要像我的網站上說filpcart訂單詳細信息頁面,但我有一些問題.....我有四個記錄到一個ORDER_NUMBER而且,當我觀看到所有記錄,然後只看到這兩個記錄order_number ...請幫助我...如何查看所有記錄到ORDER_NUMBER

+3

**警告**:如果你剛剛學習PHP,請不要使用[ mysql_query'](http://php.net/manual/en/function.mysql-query.php)接口。這是非常可怕和危險的,它在PHP 7中被刪除了。[PDO的替代品並不難學](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps -pdo-for-database-access /)以及[PHP The Right Way](http://www.phptherightway.com/)等指南介紹了最佳實踐。你的用戶數據是**不是** [正確轉義](http://bobby-tables.com/php.html),並有[SQL注入漏洞](http://bobby-tables.com/),並且可以被利用。 – tadman

回答

0
<?php 
function view_amshops_order_details(){ 
    session_start(); 
     if(!$_SESSION['UserId'])//If session doesnt exist call signin 
     { 
      signin(); //No signin function on this page nor is it included 
     } 

    $userId = $_SESSION['UserId']; 

    $conn = new mysqli('host', 'username', 'password', 'databaseName'); 

    $rs2 = $conn->query("SELECT field,field FROM user WHERE u_id='$userId'"); 
    $rs2Row = $rs2->fetch_assoc(); 
    // then use $rs2Row['tableName']; 
    global $View_Path; 
    $i=0; 

    $amshops = $conn->query("SELECT field,field,field from payment_amshops join order_amshops WHERE payment_om_id=om_id and payment_u_id='$userId'"); //Shouldnt be any reason that you would have to join the same two tables over and over so this should clear it up a bit 
    if(mysqli_num_rows($amshops) > 0){ 
     while($row = $amshops->fetch_assoc()) { 
      $order_number = $row['om_order_number']; 
      $row['size'] = strlen($i); // Not sure why you want this to be done considering you are calling the data from your db and then changing it. "$detail['size']=strlen($i);" 

     } 
    } else { 
     echo('Database came back with no results'); 
    } 
    $inner_amshops = $conn->query("SELECT field,field,field FROM addtocart_2 join category2 WHERE cart_cg_id=cg_id AND order_number='$order_number'"); 
    if(mysqli_num_rows($inner_amshops) > 0){ 
     while($row = $inner_amshops->fetch_assoc()) { 
      if(!$row['cg_pic']){ 
       $file=$View_Path.$row['cg_pic']; 
      } 
      if(!file_exists($Upload_Path.$row['cg_pic'])){ 
       $file = ""; 
      } 
     } 
    } 
    //Suggest rewriting html to get rid of smarty completly it seems because I highly recommend that you learn to carry data over echo();