Array with field orders instead of ID

Asked

Viewed 29 times

0

Good afternoon guys, I’m having a hard time here. I have two tables, cursos and alunos_inscritos. The student table has an id(auto_increment), which records the course code for each registration. I would like to generate a presence list in the type order, 1,2,3 and so on, which instead of bringing the table ID, brings the position of the array. I don’t know if I was clear. Look at my code.

$dados = connection::select("select * from alunos where id_curso=5")

foreach ($dados as $reg) {

$ordem = array($reg['id'],$ordem)

$tabela .= '<table width:100%;"> 
            <tr>
            <td>' . $ordem . '</td>
            <td>' . $reg['nome'] . '</td>
            </tr>
            </table>';

  }
  • foreach ($dados as $reg as $key) { $key is the current input of the array.

  • Didn’t work :/

  • is that this code would be foreach ($given as $key => $reg) hence the $key is the key, but could use tbm array_keys();

  • I got it right guys. Thanks.

  • How to start the $key in the second position, not to show the zero.

No answers

Browser other questions tagged

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