Foros del Web » Programando para Internet » PHP »

Como insertar los resultados de consulta?

Estas en el tema de Como insertar los resultados de consulta? en el foro de PHP en Foros del Web. Hola que tal, llevo una semana metiendole duro a aprender PHP, ahora estoy aprendiendo ha hacer consultas, hasta ahora si me arroja los resultados de ...
  #1 (permalink)  
Antiguo 31/05/2004, 12:18
 
Fecha de Ingreso: septiembre-2003
Ubicación: Cancun mexico
Mensajes: 50
Antigüedad: 20 años, 7 meses
Puntos: 0
Pregunta Como insertar los resultados de consulta?

Hola que tal, llevo una semana metiendole duro a aprender PHP, ahora estoy aprendiendo ha hacer consultas, hasta ahora si me arroja los resultados de las consultas, pero intento metarlos dentro de código html y no me queda me arroja error de : T_CONSTANT_ENCAPSED_STRING, pero le quito el código html y ningun error.
Los resultados de mi consulta van dentro de celdas y la verdad no hayo la forma de meterlos, les voy a poner mi codigo que hasta ahora llevo, en el cual no me da error ya que no hay dentro del código del resultado codigo html.

Espero alguien me pueda explicar como hacerle:

CODIGO :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<?php
include("conex.php");
$link=Conectarse();
?>
<head>
<title>Consulta a la DB</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
$result = mysql_query("select * from cd_releases",$link);
if (!$result)
{
echo("<p>Error haciendo la consulta en: " . mysql_error() . "</p>");
exit();
}
?>
<table width="760" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="760" height="44" valign="top">Estos son los datos insertados en
la DB de MY SQL con php, si quieres insertar m&agrave;s datos presiona <a href="alta.htm">aqui</a></td>
</tr>
<tr>
<td height="299" valign="top">
<?php
while ($row = mysql_fetch_array($result))
{
//variables de ejemplo
printf ($row["Artist"]);
printf ($row["Title"] );


}
mysql_free_result($result);
mysql_close($link);
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="192" height="25" valign="top">Artista</td>
<td width="232" valign="top">Titulo</td>
<td width="71" valign="top">A&ntilde;o</td>
<td width="102" valign="top">LABEL</td>
<td width="163" valign="top">N&ugrave;m pistas</td>
</tr>
<tr>
<td height="29" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
</table>

</td>
</tr>
<tr>
<td height="77">&nbsp;</td>
</tr>
</table>

</body>
</html>


MIL GRACIAS

Última edición por odilon; 31/05/2004 a las 12:20 Razón: me falta variables
  #2 (permalink)  
Antiguo 31/05/2004, 13:28
Avatar de Bizo21  
Fecha de Ingreso: abril-2004
Ubicación: Valdivia
Mensajes: 93
Antigüedad: 20 años
Puntos: 1
hola haber si te entendi tu lo que quieres es usar php y html junto es decir
que tu quieres colocar dentro de una consulta php el codigo html si es eso tendrias que hacer algo haci:
/*
<!--DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html-->
*/
<head>
<title>Consulta a la DB</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body>
</head>
<?php
include("conex.php");
$link=Conectarse();

$result = mysql_query("select * from cd_releases",$link);
if (!$result)
{
echo("<p>Error haciendo la consulta en: " . mysql_error() . "</p>");
exit();
}
echo"<table width=\"760\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<!--DWLayoutTable-->
<tr>
<td width=\"760\" height=\"44\" valign=\"top\">Estos son los datos insertados en
la DB de MY SQL con php, si quieres insertar m&agrave;s datos presiona <a href=\"alta.htm\">aqui</a></td>
</tr>
<tr>
<td height=\"299\" valign=\"top\">";
while ($row = mysql_fetch_array($result))
{
//variables de ejemplo
printf ($row["Artist"]);
printf ($row["Title"] );
}
mysql_free_result($result);
mysql_close($link);

echo"<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<!--DWLayoutTable-->
<tr>
<td width="192" height="25" valign="top">Artista</td>
<td width="232" valign="top">Titulo</td>
<td width="71" valign="top">A&ntilde;o</td>
<td width="102" valign="top">LABEL</td>
<td width="163" valign="top">N&ugrave;m pistas</td>
</tr>
<tr>
<td height="29" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
</table>

</td>
</tr>
<tr>
<td height="77">&nbsp;</td>
</tr>
</table>";
?>
</body>
</html>


es asi y cuando en codigo php hay " " o ' ' tiene que ir un \ es decir uno adelante de la comilla y otro al medio de la comilla algo asi echo" <align=\" \ " >"; os ino muestra error

prueba eso y respondes si te sirvio o no si te tiras algun erro envia el error y la funcion.
  #3 (permalink)  
Antiguo 01/06/2004, 10:25
 
Fecha de Ingreso: septiembre-2003
Ubicación: Cancun mexico
Mensajes: 50
Antigüedad: 20 años, 7 meses
Puntos: 0
Mil Gracias

Gracias mi amigo: Bizo21, ah quedado de maravilla, agradezco mucho tu ayuda, es increible como con diagonales invertidas se pueda meter el código html.

Graicas de nuevo
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 14:00.