<? include ("fichier-de-connexion.php");
// Liste les données de la table
// -------------------------------------------
$resQuery = mysql_query("SELECT * FROM ta-table");
header("Content-Type: application/csv-tab-delimited-table");
header("Content-disposition: filename=nom-du-fichier.csv");
if (mysql_num_rows($resQuery) != 0) {
// titre des colonnes
$fields = mysql_num_fields($resQuery);
$i = 0;
while ($i < $fields) {
echo mysql_field_name($resQuery, $i).";";
$i++;
}
echo "\n";
// données de la table
while ($arrSelect = mysql_fetch_array($resQuery, MYSQL_ASSOC)) {
foreach($arrSelect as $elem) {
echo "$elem;";
}
echo "\n";
}
}
?>
Mega
Code : Tout sélectionner
<input type="checkbox" name="personne[]" value="12" />
<input type="checkbox" name="personne[]" value="14" />
<input type="checkbox" name="personne[]" value="15" />
$_POST['personne'][0] //==> première case cochée, p. ex. 14
Arf, mais quel con je suis !la possibilté d'ajouter dans leur table contacts des enregistrements issus d'un fichier CSV
Tu me fais rire !Arf, mais quel con je suis !
Je te jure, je suis pas beurré hein... ! (ma tartine oui par contre)
<?php
require_once('../Connections/connection_jesuisne.php');
mysql_select_db($database_connection_jesuisne, $connection_jesuisne);
$fichier = file('../csv/export_contacts.csv');
?>
<table width="100%" border="0" align="center">
<tr>
<td bgcolor="#D2DDE3"><div align="center"><strong>Contact</strong></div></td>
<td bgcolor="#D2DDE3"><div align="center"><strong>Email</strong></div></td>
<td bgcolor="#D2DDE3"><div align="center"><strong>Téléphone</strong></div></td>
<td bgcolor="#D2DDE3"><div align="center"><strong>Importer</strong></div></td>
</tr>
<?
$mots = array();
$i = 0;
foreach($fichier AS $fic)
{
$mots[$i] = explode(";", $fic);
?>
<tr>
<td><div align="center" class="Style1"><?php echo $mots[$i][0]; ?></div></td>
<td><div align="center" class="Style1"><?php echo $mots[$i][1]; ?></div></td>
<td><div align="center" class="Style1"><?php echo $mots[$i][2]; ?></div></td>
<td><div align="center" class="Style1"><?php echo $mots[$i][3]; ?></div></td>
</tr>
<? $i++; }?>
</table>
Maintenant, j'ai deux questions majeures :Code : Tout sélectionner
John;[email protected];12345678
Rudy;[email protected];78787878
Jérémy;[email protected];45454545
anne;[email protected];23562356<?php
$fichier=file('ton_csv.txt');
$i=0;
foreach($fichier as $ligne)
{
$donnees=explode(';',$ligne);
foreach($donnees as $val)
{
$new_fichier[$i][]=$val;
}
$i++;
}
echo '<pre>';
print_r($new_fichier);
echo '</pre>';
?>
tu obtiendras ça :
<form name="form1" method="post" action="">
<table width="100%" border="0" align="center">
<tr>
<td bgcolor="#D2DDE3"><div align="center"><strong>Contact</strong></div></td>
<td bgcolor="#D2DDE3"><div align="center"><strong>Email</strong></div></td>
<td bgcolor="#D2DDE3"><div align="center"><strong>Importer</strong></div></td>
</tr>
<?
$mots = array();
$i = 0;
foreach($fichier AS $fic)
{
$mots[$i] = explode($delimiteur, $fic);
?>
<tr>
<td><div align="center" class="Style1"><?php echo strtr(($mots[$i][$NumColNom-1]), "\"", " "); ?></div></td>
<td><div align="center" class="Style1"><?php echo strtr(($mots[$i][$NumColEmail-1]), "\"", " "); ?></div></td>
<td><div align="center" class="Style1">
<label>
<input type="checkbox" name="<?php echo "checkbox".$i;?>" value="checkbox">
</label>
</div></td>
</tr>
<? $i++; }
}
}
?>
</table>
</form>
J'arrive bien à afficher un tableau dynamique contenant le fichier csv récupéré en rajoutant en plus ma checkbox mais je ne sais pas ensuite comment le traiter pour faire en sorte que les enregistrements pour lesquels la checkbox est cochée, soit pris en compte dans ma future requete INSERT INTO.Pas bon cette syntaxe !Code : Tout sélectionner
<input type="checkbox" name="<?php echo "checkbox".$i;?>" value="checkbox">
Code : Tout sélectionner
<input type="checkbox" name="contact[]" value="la valeur du contact"><?php
echo print_r($_POST['contact'],true);
?>
Tu obtiendras un array() avec les emails cochés