Foros del Web » Programando para Internet » PHP »

pasar los datos de msql a excel

Estas en el tema de pasar los datos de msql a excel en el foro de PHP en Foros del Web. como puedo hacer esto tengo el siguiente cod qpero me manda errores Código PHP: Warning :  mysql_num_fields ():  supplied argument is not a valid MySQL result resource in  / home / rymchile / public_html ...
  #1 (permalink)  
Antiguo 20/11/2006, 19:29
Avatar de a83
a83
 
Fecha de Ingreso: noviembre-2005
Ubicación: Santiago de chile
Mensajes: 637
Antigüedad: 18 años, 5 meses
Puntos: 1
pasar los datos de msql a excel

como puedo hacer esto tengo el siguiente cod qpero me manda errores

Código PHP:
Warningmysql_num_fields(): supplied argument is not a valid MySQL result resource in /home/rymchile/public_html/php/Personal/excel.php on line 5

Warning
mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/rymchile/public_html/php/Personal/excel.php on line 11

Warning
Cannot modify header information headers already sent by (output started at /home/rymchile/public_html/php/conexion.php:2in /home/rymchile/public_html/php/Personal/excel.php on line 35

Warning
Cannot modify header information headers already sent by (output started at /home/rymchile/public_html/php/conexion.php:2in /home/rymchile/public_html/php/Personal/excel.php on line 37

Warning
Cannot modify header information headers already sent by (output started at /home/rymchile/public_html/php/conexion.php:2in /home/rymchile/public_html/php/Personal/excel.php on line 38

Warning
Cannot modify header information headers already sent by (output started at /home/rymchile/public_html/php/conexion.php:2in /home/rymchile/public_html/php/Personal/excel.php on line 39
no matching records found 


codigo


Código PHP:
<?php
include("../conexion.php");     
$sql="select * from ingreo_personal order by FECHA desc";
//$result = conexionl($sql); 
$count mysql_num_fields($result);

for (
$i 0$i $count$i++){
    
$header .= mysql_field_name($result$i)."\t";
}

while(
$row mysql_fetch_row($result)){
  
$line '';
  foreach(
$row as $value){
    if(!isset(
$value) || $value == ""){
      
$value "\t";
    }else{

      
$value str_replace('"''""'$value);

      
$value '"' $value '"' "\t";
    }
    
$line .= $value;
  }
  
$data .= trim($line)."\n";
}

  
$data str_replace("\r"""$data);


if (
$data == "") {
  
$data "\nno matching records found\n";
}


header("Content-type: application/octet-stream");

header("Content-Disposition: attachment; filename=clientes.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo 
$header."\n".$data
?> 
:arriba:
  #2 (permalink)  
Antiguo 20/11/2006, 19:47
 
Fecha de Ingreso: diciembre-2004
Mensajes: 207
Antigüedad: 19 años, 4 meses
Puntos: 0
Hola, Yo uso este código y no me da problemas. Revisalo.

Código PHP:
include("../../i/configuracion.php");
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Listado_$colegio_deptal.xls"); 
?>

<html>
<head>
<title>Listado General - CQFP</title>
</head>
<body>
<?PHP
if ($_SESSION['nivel'] <= 2)
{
$consulta="SELECT cqfp,apellido_paterno,apellido_materno,nombre,colegio_deptal,fecha_habilitacion,documento,tipo_docum
            FROM colegiados
            WHERE colegio_deptal='$depto' 
            ORDER BY apellido_paterno"
;
$resultado=mysql_query($consulta,$con) or die("Error al buscar datos, referente al bloque de contenidos de CQFP");
if(
mysql_num_rows($resultado)>0

?>

<table width="100%"  border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="8"><div align="center"><font size="+2" color="#FF0000"><b>Listado General de los AGREMIADOS del Colegio Qu&iacute;mico Farmac&eacute;utico del Per&uacute; <br>
      Departamento de <?=$colegio_deptal?> </b></font></div></td>
  </tr>
  <tr>
    <td><strong>Colegiatura</strong></td>
    <td><b>Apellido Paterno</b></td>
    <td><b>Apellido Materno</b></td>
    <td><b>Nombre(s)</b></td>
    <td><b>Departamento</b></td>
    <td><b>Fecha de<br> 
    habilitaci&oacute;n</b></td>
    <td><b>Tipo Documento</b></td>
    <td><b>Documento </b></td>
  </tr>
<?
//-------Inicio de la region repetida
    
while($row mysql_fetch_assoc($resultado))
    { 
    
extract($row);
?>
  <tr>
    <td><div align="center"><?=$cqfp ?>
    </div></td>
    <td><?=$apellido_paterno ?></td>
    <td><?=$apellido_materno?></td>
    <td><?=$nombre?></td> .... (resto del código)

Última edición por Cluster; 20/11/2006 a las 20:06
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:07.