Data grid with function 0 in the rest PHP or PHP+Ajax

Asked

Viewed 112 times

1

I’m an Intermediate Programmer, and I’m at an impasse, I need to display some items and what’s missing I need you to fill out with a mayor model. Let’s explain the logic ok?

In My Table (I will use examples ok?) ITEMS, you can add a maximum of 20 ITEMS (Up to ae, everything ok.). Let’s assume I have 12 rows in the ITEMS table like this [id]1[tipo_item]1. Namely from ID1 i have 12 items. To complete the limit of 20 missing 8, correct?

Now I need to show off like this:

Items: (id is hidden no need to show)(ie no need to pull the variable $id.)

[tipo1]  [tipo1]  [tipo1]  [tipo1]

[tipo1]  [tipo1]  [tipo1]  [tipo1]

[tipo1]  [tipo1]  [tipo1]  [tipo1]

(now comes the problem) the 8 "remaining voids" needed you to show so

[Vazio]  [Vazio]  [Vazio]  [Vazio]

[Vazio]  [Vazio]  [Vazio]  [Vazio]

I need the code to show all items in grid, in a total amount per page I select. but I need it to do a type account

20 - $quantidade de linhas

(in the case remaining 8) and the one left over shows an empty slot. (or an. x of images (e.g., empty.png)(or a text (empty)

  • See if this sql solution helps http://forum.imasters.com.br/topic/288300-consulta-sql-difcil/#entry1048056

  • 2

    It is good to take half of these tags there and decide if you want in PHP or JS. I’m responding in PHP, but since you’re an intermediate programmer, I think it’s easy to adapt to JS if you need.

1 answer

4

As this is a basic issue, I tried to make a very didactic code:

<?php
   // Primeiro, vamos pegar um array com doze ítens para teste:
   $itens = array(
      'um', 'dois', 'tres', 'quatro', 'cinco', 'seis',
      'sete', 'oito', 'nove', 'dez',' onze', 'doze'
   );

   // depois, vamos contar o número de ítens 
   $qtdItens= count( $itens );

   // Aqui você define quantas colunas e linhas quer:
   $numColunas= 4;
   $numLinhas= 5;
   // O número de linhas poderia ser calculado automaticamente com facilidade,
   // baseado no número de colunas, mas vou me ater ao enunciado.

   for( $l = 0; $l < $numLinhas; $l++ ) {
      for( $c = 0; $c < $numColunas; $c++ ) {
         // vamos calcular de que ítem se trata:
         $itemAtual = $c + ( $l * $numColunas );

         // e decidir se imprimimos o [ítem] ou [Vazio]
         if( $itemAtual < $qtdItens) {
             echo '['.$itens[$itemAtual].']';
         } else {
             echo '[Vazio]';
         }
      }
      echo "\n"; //trocar por "<br>\n" se for exibir em página
   }
?>

See working on IDEONE.

  • Wow, how long, thanks fierce, I found this account lost, and I came to thank (even having already solved at the time). Hugção!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.