php - Mysql array data not display table -


i have use mysql table values on table ,that values used table .i got array values

first table query:

    $ordersdetail = "select * `order_item` `order_id`='".$orderid ."'"; $customerorder = mysql_query($ordersdetail );                    $i=0;              while($rows = mysql_fetch_array($customerorder ))              {                 $orderproduct= $rows['order_product_id'];                 $orderids= $rows['order_id'];                 $productid[$i] = $rows['product_id'];                 $sizeid[$i] = $rows['size_id'];                   $colorid[$i] = $rows['color_id'];                   $quantiy = $rows['order_quantity'][$i];                    $price = $rows['unit_price'][$i];                   $subtotal = $rows['sub_total'];                   $customerccode = $rows['record_status'];                   $customerphone = $rows['created_time'];                   $i++;                 }      

table column productid array values used table:

given:

       for($i=0;$i<count($productid);$i++)                {          $product = "select * `product` `product_id`='".$productid[$i]."'"; $products = mysql_query($product);               while($rows = mysql_fetch_array($products))                         {                     $productnames = $rows['product_name'];                  }                    }    color id used :          for($i=0;$i<count($colorid);$i++)                  {         $color = "select * `color` `color_id`='".$colorid[$i] ."'"; $cname = mysql_query($color);               while($rows = mysql_fetch_array($cname))                         {                     $colorname = $rows['color_name'];                }                   } 

same way used values table

my questions values displayed table continuely

         table structure              $message .= "<table width='100%' border='1' cellspacing='0' cellpadding='1'>           <thead>          <tr style='background: #eee;'>           <th><strong>quantity</strong> </th>           <th><strong>productname</strong> </th>          <th><strong>size</strong> </th>            <th><strong>style</strong> </th>           <th><strong>price</strong> </th>           <th><strong>total</strong> </th>              </tr>                  ";           for($i=0;$i<count($productid);$i++)                {                        $message .=" <tr style='color: #c40000;'>                       <th>" .$quantiy. "</th>                      <th>" .$productnames. "</th>                          <th>" .$sizename. "</th>                             <th>" .$colorname. "</th>                                <th>" . $price. "</th>                                    <th>" . $subtotal. "</th>                                                           </tr>";                            } 

this format correct more values not displayed first values display multiple time

this hard 1 answer because there there lot of issues going on....

first off....unless private/internal application, cant place variables directly query...look proper database class, can recommend : http://www.imavex.com/php-pdo-wrapper-class/

secondly, mixing php code , html much...i'm not going go in general want keep stuff seperate...research mvc programming patterns.

now answer question...the reason seeing same data repeat because you using 1 variable getting overwritten each time...ie. $quantiy (which spelled wrong fyi)...so hack approach, assign array , use $i counter on doing $productid

a better approach stuff in loop , avoid assign vars in first place...i'm assuming have assign stuff message var...if can skip , echo out directly better.

$ordersdetail = "select * `order_item` `order_id`='".$orderid ."'"; $customerorder = mysql_query($ordersdetail ); $i=0; while($rows = mysql_fetch_array($customerorder ))     $product = "select * `product` `product_id`='".$row[$i]."'";     $products = mysql_query($product);     $color = "select * `color` `color_id`='".$colorid[$i] ."'";     $cname = mysql_query($color);      create table $rows data directly , when goto      color/size stuff through in there.  } 

now i'm not 100% sure work similar above single query using joins

select * `order_item` left join product on order_item.productid = product.productid left join color on order_item.colorid = color.colorid order_item.`order_id`='".$orderid ."' 

please pardon syntax/naming conventions...the above command not run on system, meant give idea on do.


Comments