php - mysql query need some loop or array -


i need mysql query. have several products same order_id , want show shows 1 product of 30 products.

if (!$_get['orderid']) {     }  else {     $order_id = ereg_replace("[^0-9]", "", $_get['orderid']); // filter numbers security }  $sqlcommand = "select * tabell_order_product order_id='$order_id'";  $query = mysqli_query($myconnection, $sqlcommand) or die (mysqli_error());  while ($row = mysqli_fetch_array($query)) {      $product_id = $row["product_id"];  }  mysqli_free_result($query);  //--------------------------------------------------------------------------------- $sqlcommand = "select * tabell_product product_id='$product_id'";  $query = mysqli_query($myconnection, $sqlcommand) or die (mysqli_error());  while ($row = mysqli_fetch_array($query)) {      $model = $row["model"];     $location = $row["location"]; }  mysqli_free_result($query);  //---------------------------------------------------------------------------------  $sqlcommand = "select * tabell_product_description product_id='$product_id'";  $query = mysqli_query($myconnection, $sqlcommand) or die (mysqli_error());  while ($row = mysqli_fetch_array($query)) {      $name = $row["name"]; }  mysqli_free_result($query);  $output .= '<tr>     <td>' . $product_id . '</td>     <td>' . $name . '</td>     <td>' . $model . '</td>     <td>' . $location . '</td>   </tr>';?> 

why calling three queries if can done in single query

try this,

<?php     $sqlcommand = "select t2.product_id,t2.name,t3.model,t3.location        tabell_order_product t1, tabell_product t2, tabell_product_description t3         t1.order_id='$order_id' , t2.product_id=t3.product_id";      $query = mysqli_query($myconnection, $sqlcommand) or die (mysqli_error());      while ($row = mysqli_fetch_array($query,mysqli_assoc)) {          $product_id=$row['product_id'];         $name=$row['name'];         $model=$row['model'];         $location=$row['location'];         $output .= '<tr>             <td>' . $product_id . '</td>             <td>' . $name . '</td>             <td>' . $model . '</td>             <td>' . $location . '</td>         </tr>';     } ?> 

read mysqli-fetch-array


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -