How can I display a SQL query result in an HTML table without cutting off long content?
The issue I am facing is that the cell length in my table does not adjust to fit the length of the content, making it difficult to read.
In each cell, there is an <input>
tag so I can directly modify data and trigger an update query with the onChange
event.
This is how I generate my table:
$texte = "<table class='table table-bordered table-sm' ><thead>$table_header</thead>";
$texte .= "<tbody>";
$nb_ligne ="Number of rows: ".pg_num_rows($result);
while($row = pg_fetch_row($result)){
$texte .= "<tr>";
foreach ($row as $value){
$texte .= "<td><input class='form-control' value='$value' onchange=''></td>";
}
$texte .= "</tr>";
}
$texte .= "</tbody></table>";
$table_header
is defined above within a switch{} case''
statement where different strings are used depending on the case. For example:
switch ($query){
case 'Aiguillage_Etat':
$requete = "select projet.projet_nom, aiguilalge.aig_etat from projet inner join aiguillage on aiguillage.aig_id = projet.projet_id where aiguillage.aig_etat $filtre;";
$table_header = "<th>Nom projet</th><th>Etat aiguillage</th>";
break;
}
I utilize AJAX to change the content of a <div>
, where my table is displayed:
<div id="tableau_resultat"></div>
Even after trying to adjust the width of the <th>
elements, I have been unsuccessful in adapting to the length of the content.
If possible, please provide guidance on what I may be doing wrong in this approach or if there are any insights I may be missing.