Create custom variables

0

Well, I have a flea here, behind the ear and I can not solve the following problem:

  $select = $mysqli->query("SELECT * FROM payments WHERE client_email='$xemail'");
  $row = $select->num_rows;
  $linhas = 0;
  while($linhas < $row) {
  $get = $select->fetch_array();
  $top_1 = $get[0];
  $top_2 = $get[1];
  $top_3 = $get[2];
  $top_4 = $get[3];
  $top_5 = $get[4];
  $top_6 = $get[5];
  $top_7 = $get[6];
  $top_8 = $get[7];
  $top_9 = $get[8];
  $top_10 = $get[9];
  $top_11= $get[10];
  $top_12 = $get[11];
  $linhas++;
  }
  echo '<div id="transaction_id">'.$top_2.'</div>';
  echo '<div id="client_email">'.$top_3.'</div>';
  echo '<div id="payment_method">'.$top_4.'</div>';
  echo '<div id="payment_method_transaction">'.$top_5.'</div>';
  echo '<div id="transaction_status">'.$top_6.'</div>';
  echo '<div id="transaction_date">'.$top_7.'</div>';
  echo '<div id="transaction_date_last">'.$top_8.'</div>';
  echo '<div id="product">'.$top_9.'</div>';
  echo '<div id="product_value">'.$top_10.'</div>';
  echo '<div id="client_name">'.$top_11.'</div>';
  echo '<div id="status">'.$top_12.'</div>';

Basically this will get all the purchases made to that customer's email. But the problem is that the variables could not be called $ top_1, they should get an additional number each time the loop repeats, after top_12 and goes back to top_1, instead of top_1 and top_13, and so on. .. and give an echo in the variable to be able to get it in CSS ... I do not know if this title would be ideal, but I looked for it on Google and found nothing, I honestly did not know how to search for this problem ... :(

What I want to do is take all the data from the purchases and display them on a page to the customer. The system will read about 5 records and then it will display page 2, and so on ... I do not even know if this script is the best way to do that ... but it was the one I tested and gave + - right. Is it possible to create these variables with different names as the loop repeats itself? Is there a better way to do this?

    
asked by anonymous 21.07.2016 / 19:18

2 answers

1

I think this will solve your problem:

<?php
    $count = 0;
    $res = $mysqli->query("SELECT * FROM payments WHERE client_email='$xemail'");

    while($row = $res->fetch_array()){
      $top[$count] = $row['nomeDaColuna'];
      $count++;
    }

    echo '<div id="transaction_id">'.$top[0].'</div>';
    echo '<div id="client_email">'.$top[1].'</div>';
    echo '<div id="payment_method">'.$top[2].'</div>';
    echo '<div id="payment_method_transaction">'.$top[3].'</div>';
    echo '<div id="transaction_status">'.$top[4].'</div>';
    echo '<div id="transaction_date">'.$top[5].'</div>';
    echo '<div id="transaction_date_last">'.$top[6].'</div>';
    echo '<div id="product">'.$top[7].'</div>';
    echo '<div id="product_value">'.$top[8].'</div>';
    echo '<div id="client_name">'.$top[9].'</div>';
    echo '<div id="status">'.$top[10].'</div>';
?>
    
21.07.2016 / 19:54
2

The right one would be to use a multidimensional array. And it's also not a good idea to use mysqlli

21.07.2016 / 19:32