How to show orders per client from mysql

0

I am asking the question again, with more information and data. So you can understand me better:

"I edit the question again.

I want to show, the orders to each client: Reading from the mysql.

I have the record as follows:

Validation of the user charge

<?php
  session_start();

  if(!isset($_SESSION['cargo']) || $_SESSION['cargo'] != 2){
    header('index.php');
    $idusuario = $_SESSION['id']
  }
?>

Table structure:

      <?php
        require('conexion.php');
       
        $query="SELECT *  FROM historial WHERE id = '$idusuario' ORDER BY fecha DESC;";

        $resultado=$mysqli->query($query);
        
      ?>      
      <table id="orders" cellspacing="0" class="orders"> 
        <thead>
          <tr class="centro">
            <th >Order</th>
            <th >Fecha</th>
            <th >Cliente</th>>
            <th >Referencia</th>
            <th >Familia</th>
            <th >Ojo Derecho</th>
            <th >Ojo Izquierdo</th>
          </tr>
          <tbody>       
            <?php 
            while($row=$resultado->fetch_assoc()){ ?>
              <tr>
                <td><?php echo $row['ordern'];?>
                </td>
                <td>
                  <?php echo $row['fecha'];?>
                </td>
                <td>
                  <?php echo $row['cliente'];?>
                </td>
                <td>
                  <?php echo $row['referencia'];?>
                </td>
                <td>
                  <?php echo $row['familia'];?>
                </td>
                <td>
                  <?php echo $row['od'];?>
                </td>
                <td>
                  <?php echo $row['oi'];?>
                </td> 
              </tr>
            <?php } ?>
          </tbody>
        </table>
 Such as it is: I get an error in this line:

while($row=$resultado->fetch_assoc()){ ?>

"Call to a member function fetch_assoc ()"

I have tried several things according to the answers, but I get an error. I can not get to show me the client's. "

    
asked by Javier Avila Fernandez 02.11.2017 в 16:29
source

1 answer

0

Hello colleague try this

 $query="SELECT *  FROM historial WHERE id = '$idusuario' ORDER BY fecha DESC";
  $mysqli->query($query);
  $resultado= $mysqli->use_result();

  ?>      
  <table id="orders" cellspacing="0" class="orders"> 
    <thead>
      <tr class="centro">
        <th >Order</th>
        <th >Fecha</th>
        <th >Cliente</th>>
        <th >Referencia</th>
        <th >Familia</th>
        <th >Ojo Derecho</th>
        <th >Ojo Izquierdo</th>
      </tr>
      <tbody>       
        <?php 
        while($row=$resultado->fetch_assoc()){ ?>
          <tr>
            <td><?php echo $row['ordern'];?>
            </td>
            <td>
              <?php echo $row['fecha'];?>
            </td>
            <td>
              <?php echo $row['cliente'];?>
            </td>
            <td>
              <?php echo $row['referencia'];?>
            </td>
            <td>
              <?php echo $row['familia'];?>
            </td>
            <td>
              <?php echo $row['od'];?>
            </td>
            <td>
              <?php echo $row['oi'];?>
            </td> 
          </tr>
        <?php } ?>
      </tbody>
    </table>
    
answered by 30.03.2018 в 06:37