Código PHP:
<?php
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=lista.xls");
$conectar = mysql_connect("localhost","dv000110","oficinas8968mucha");
mysql_select_db ("dv000110_lista", $conectar) OR die ("Error en la Conexión");
$result = mysql_query("select * from listado", $conectar);
while ($row = mysql_fetch_array($result))
{
$a1 = $row["codigo"];
$a2 = $row["detalle"];
$a3 = $row["precio"];
$a4 = $row["ganancia"];
$a5 = $row["categoria"];
}
while ($row = mysql_fetch_array($result));
}
else
{
?>
<table align="center">
<td>
<b><font align="center" size="6" color="#ff0000" face="Tahoma">
No existen registros, o la fecha introducida</font></b></td>
<tr><td align="center">
<b><font align="center" size="6" color="#ff0000" face="Tahoma">
no es correcta</font></b></td></tr>
</table>
<?
}
?>
<!-- Fin PHP y comienza HTML -->
<html>
El error esta en que while se cierra y no tiene else... por lo tanto... para saber si tienes registros o no haces lo siguiente
Código PHP:
<?php
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=lista.xls");
$conectar = mysql_connect("localhost","dv000110","oficinas8968mucha");
mysql_select_db ("dv000110_lista", $conectar) OR die ("Error en la Conexión");
$x = 0;
$result = mysql_query("select * from listado", $conectar);
while ($row = mysql_fetch_array($result))
{
$a1 = $row["codigo"];
$a2 = $row["detalle"];
$a3 = $row["precio"];
$a4 = $row["ganancia"];
$a5 = $row["categoria"];
$x++; //si x aumenta hay registros
}
if (x < 1){
$html = '
<table align="center">
<td>
<b><font align="center" size="6" color="#ff0000" face="Tahoma">
No existen registros, o la fecha introducida</font></b></td>
<tr><td align="center">
<b><font align="center" size="6" color="#ff0000" face="Tahoma">
no es correcta</font></b></td></tr>
</table>';
print $html;
}
?>
<!-- Fin PHP y comienza HTML -->
<html>