espero qu me piedan ayudar
salu2
EJEMPLO DE USO CON ARCHIVO .CSV
Código PHP:
<?php
include("config.php");
include("conectar.php");
if($subir_archivo == 1) {
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="7%"><div align="center"><strong>ID</strong></div></td>
<td width="55%"><div align="center"><strong>Material</strong></div></td>
<td width="38%"><div align="center"><strong>Precio</strong></div></td>
</tr>
<?
$fp = fopen("excel/excel.csv","r");
$data = fgetcsv($fp, 1000, ",");
$num = 1;
do{
$material = $data['0'];
$costo = $data['1'];
$sql = "SELECT * FROM materiales WHERE material='$material'";
$result = mysql_query($sql) or die (mysql_error());
if($row = mysql_fetch_array($result)) {
$des = $row['descuento'];
$des /= 100;
$precio = $costo*$des;
$precio2 = $costo - $precio;
$precio2 = number_format($precio2, 2, '.', '');
echo ' <tr>
<td width="7%"><div align="center">'.$num.'</div></td>
<td width="55%">'.$material.'</td>
<td width="38%"><div align="center">'.$precio2.'</div></td>
</tr>';
$ano = date('Y');
$mes = date('m');
$dia = date('j');
$fecha = $ano. '/'.$mes.'/'.$dia;
$update = "UPDATE materiales SET costo='$costo' WHERE material='$material'";
mysql_query($update) or die (mysql_error());
$sql2 = "UPDATE config SET valor='$fecha' WHERE nombre='fecha'";
mysql_query($sql2) or die (mysql_error());
$num++;
}else{
?>
<script language="javascript">
alert("El material <? echo $data['0']; ?> no existe. Favor de agregarlo.");
location.href = "index.php?pag=nuevo_producto&material=<? echo $material; ?>&precio=<? echo $costo; ?>&hide=1";
</script>
<?
}
}while($data = fgetcsv ($fp, 1000, ","));
}else{
?>
<script language="javascript">
alert("Error!!!");
history.back(-1);
</script>
<?
}
?>
</table>