Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
how import rows from csv file into php html table then add search functionaly with javascript?

I have a CSV file that contains books, the columns in it are:

book_id,name, date_published

it looks like this for example

I need to put this data into an HTML table using PHP, then use javascript to add a search function, that makes it so that if the rows match with the input only then will the table be visible?

I'm completely stumped and would appreciate an easy understanding of the solution!

well I tried to import the CSV file in PHP but I can't seem to get it into an array I tried other methods some got me to the javas cript bit but nothing successful

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can open your CSV file and display it in a table as follows:

<?php
// Open the CSV file
$fcsv = fopen( 'filename.csv', 'r' );
// Get header row
$row = fgetcsv( $fcsv );
// Output start of table & header row
?>
<table>
  <thead>
    <tr>
      <td><?= $row[0] ?></td>
      <td><?= $row[1] ?></td>
      <td><?= $row[2] ?></td>
      <td><?= $row[3] ?></td>
      <td><?= $row[4] ?></td>
      <td><?= $row[5] ?></td>
      <td><?= $row[6] ?></td>
    </tr>
  </thead>
  <tbody>
<?php
// Loop through rest of rows in CSV
while ( ( $row = fgetcsv( $fcsv ) ) !== false )
{
?>
    <tr>
      <td><?= $row[0] ?></td>
      <td><?= $row[1] ?></td>
      <td><?= $row[2] ?></td>
      <td><?= $row[3] ?></td>
      <td><?= $row[4] ?></td>
      <td><?= $row[5] ?></td>
      <td><?= $row[6] ?></td>
     </tr>
<?php
}
?>
  </tbody>
</table>

For the Javascript filtering, you should look at the DataTables JavaScript plugin... it's very simple to set up (see examples on the website) and can search, order & filter data in a variety of ways depending on your needs.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda