Foros del Web » Programando para Internet » PHP »

Html en php

Estas en el tema de Html en php en el foro de PHP en Foros del Web. hola a todos.. Tengo este codigo @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código php: Ver original <table border="0" cellspacing="2">             <tr>       ...
  #1 (permalink)  
Antiguo 11/10/2008, 20:23
Avatar de after  
Fecha de Ingreso: junio-2006
Ubicación: De marte
Mensajes: 791
Antigüedad: 17 años, 10 meses
Puntos: 10
Html en php

hola a todos..

Tengo este codigo

Código php:
Ver original
  1. <table border="0" cellspacing="2">
  2.             <tr>
  3.               <td>Pelicula</td>
  4.               <td>Idioma</td>
  5.               <td>&nbsp;</td>
  6.               <td>&nbsp;</td>
  7.             </tr>
  8.             <?php do { ?>
  9.             <tr>
  10.               <td><?php echo $row_Record['name_movie']; ?></td>
  11.               <td><?php echo $row_Record['lenguage']; ?></td>
  12.               <td><a href="Detalle.php?recordID=<?php echo $row_Record['name_movie']; ?>"> Ver mas&nbsp; </a></td>
  13.               <td>&nbsp;</td>
  14.             </tr>
  15.             <?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>
  16.           </table>

pero necesito insertar ese codigo dentro de una etiqueta php <? ?> asi

Código php:
Ver original
  1. <?php <table border="0" cellspacing="2">
  2.             <tr>
  3.               <td>Pelicula</td>
  4.               <td>Idioma</td>
  5.               <td>&nbsp;</td>
  6.               <td>&nbsp;</td>
  7.             </tr>
  8.             <?php do { ?>
  9.             <tr>
  10.               <td><?php echo $row_Record['name_movie']; ?></td>
  11.               <td><?php echo $row_Record['lenguage']; ?></td>
  12.               <td><a href="Detalle.php?recordID=<?php echo $row_Record['name_movie']; ?>"> Ver mas&nbsp; </a></td>
  13.               <td>&nbsp;</td>
  14.             </tr>
  15.             <?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>
  16.           </table> ?>

por obvias razones asi no funciona.
así que hice esto
Código php:
Ver original
  1. <? echo ('<table border="0" cellspacing="2">
  2.            <tr>
  3.              <td>Pelicula</td>
  4.              <td>Idioma</td>
  5.              <td>&nbsp;</td>
  6.              <td>&nbsp;</td>
  7.            </tr>');?>
  8.             <?php do { ?><?
  9.             echo ('<tr>
  10.              <td>'); ?><?php echo $row_Record['name_movie']; ?><? echo ('</td>
  11.              <td>'); ?><?php echo $row_Record['lenguage']; ?><? echo ('</td>
  12.              <td><a href="Detalle.php?recordID="'); ?> <?php echo $row_Record['name_movie']; ?><? echo ('"> Ver mas&nbsp; </a></td>');?>
  13.               <? echo ('<td>&nbsp;</td>
  14.            </tr>'); ?>
  15.             <?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>
  16.           <? echo ('</table>');
  17.         }
  18.  
  19.  
  20.  ?>
pero me da error en la linea 77 que en este caso aqui seria la linea 15:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

<?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>.

como paso todo lo que es html para que php lo coja? o como ago para poder meter el codigo dentro php (<? ?>)
__________________
@ivancamiloGo

Última edición por after; 11/10/2008 a las 20:31
  #2 (permalink)  
Antiguo 11/10/2008, 21:17
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Html en php

Ese error que te sale es que tienes un error en tu consulta SQL, imprime el valor mysql_error() para ver porque te genera ese error.

Saludos.
  #3 (permalink)  
Antiguo 11/10/2008, 21:44
Avatar de after  
Fecha de Ingreso: junio-2006
Ubicación: De marte
Mensajes: 791
Antigüedad: 17 años, 10 meses
Puntos: 10
Respuesta: Html en php

al hacerlo me sale
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1
y si miro el log sale
[12-Oct-2008 05:36:23] PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in .....
... en esta linea.
<?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>
aunque no creo que sea problema de consulta ya que usando el mismo codigo en otra parte la hace correctamente. debe ser por la forma en que estoy insertando el codigo ya que lo necesito insertar dentro de <?php ?> y el codigo contiene html.
había una forma diferente de hacerlo sin el echo. pero no me acuerdo..puede que sea por eso... alternativas?
__________________
@ivancamiloGo
  #4 (permalink)  
Antiguo 11/10/2008, 21:56
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Html en php

El problema reside en tu variable $Record no en el HTML ni nada mas.
Muestranos el contenido de tu variable $Record, al parecer tienes algun error de sintaxis.
  #5 (permalink)  
Antiguo 11/10/2008, 22:05
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Respuesta: Html en php

La otra forma es así:

Código PHP:
echo<<<HTML
...html html ...
HTML; // Cierra el echo con esta línea 
O simplemente cerrar ?> antes del html y volver a abrir <?PHP cuando haya más código.

Pero coincido en que parece un problema de la consulta, ya que te dice que $Record no contiene un resultado de una consulta válida, o bien en algún punto se perdió el valor de $Record. Verificá el resto del código también y contanos...

Saludos.
  #6 (permalink)  
Antiguo 12/10/2008, 13:45
Avatar de after  
Fecha de Ingreso: junio-2006
Ubicación: De marte
Mensajes: 791
Antigüedad: 17 años, 10 meses
Puntos: 10
Respuesta: Html en php

se presenta error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
cuando tengo esas lineas en una function funcion() { ..... }
cuando no lo esta funciona bien :S
__________________
@ivancamiloGo
  #7 (permalink)  
Antiguo 12/10/2008, 13:49
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Html en php

Muestranos el resto del codigo.

EDIT: Ya que dices que tienes ese codigo dentro de una funcion, y no funciona pero cuando no lo esta si lo hace es que las funciones no pueden ver las variables que estan fuera de ella a menos que tu las definas como variables globales. Si defines la variable $Record como una variable global tu funcion si será capaz de verla.

http://www.php.net/global
  #8 (permalink)  
Antiguo 12/10/2008, 16:57
Avatar de after  
Fecha de Ingreso: junio-2006
Ubicación: De marte
Mensajes: 791
Antigüedad: 17 años, 10 meses
Puntos: 10
Respuesta: Html en php

ya di con el chiste....
el problema era por los juegos de registro, pero no en ellos si no por el archivo de conexión... duplique tal archivo, le cambie el nombre, en el código le puse el duplicado y funciono :O va bien.
aunque no se por que da problema si uso el mismo archivo de conexión... no debería no?
aunque cuando lo sigo usando con function no funciona
el $record es parte de un juego de registros.. como lo "globalizo"
__________________
@ivancamiloGo

Última edición por after; 12/10/2008 a las 17:57
  #9 (permalink)  
Antiguo 12/10/2008, 18:05
Avatar de after  
Fecha de Ingreso: junio-2006
Ubicación: De marte
Mensajes: 791
Antigüedad: 17 años, 10 meses
Puntos: 10
Respuesta: Html en php

el codigo:
Código php:
Ver original
  1. <?php require_once('../Connections/basbase.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.  
  8.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  9.  
  10.   switch ($theType) {
  11.     case "text":
  12.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13.       break;    
  14.     case "long":
  15.     case "int":
  16.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17.       break;
  18.     case "double":
  19.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  20.       break;
  21.     case "date":
  22.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23.       break;
  24.     case "defined":
  25.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26.       break;
  27.   }
  28.   return $theValue;
  29. }
  30. }
  31.  
  32. mysql_select_db($database_basbase, $basbase);
  33. $query_Recordset1 = "SELECT * FROM list_movies";
  34. $Recordset1 = mysql_query($query_Recordset1, $basbase) or die(mysql_error());
  35. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  36. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  37. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  38. <html xmlns="http://www.w3.org/1999/xhtml">
  39. <head>
  40. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  41. <title>Documento sin t&iacute;tulo</title>
  42. </head>
  43.  
  44. <body>
  45. <table border="1">
  46.   <tr>
  47.     <td>ID</td>
  48.     <td>name_movie</td>
  49.     <td>lenguage</td>
  50.     <td>Sub</td>
  51.     <td>year</td>
  52.     <td>tipe</td>
  53.     <td>format</td>
  54.     <td>mn</td>
  55.     <td>info</td>
  56.     <td>img</td>
  57.   </tr>
  58.   <?php do { ?>
  59.     <tr>
  60.       <td><?php echo $row_Recordset1['ID']; ?></td>
  61.       <td><?php echo $row_Recordset1['name_movie']; ?></td>
  62.       <td><?php echo $row_Recordset1['lenguage']; ?></td>
  63.       <td><?php echo $row_Recordset1['Sub']; ?></td>
  64.       <td><?php echo $row_Recordset1['year']; ?></td>
  65.       <td><?php echo $row_Recordset1['tipe']; ?></td>
  66.       <td><?php echo $row_Recordset1['format']; ?></td>
  67.       <td><?php echo $row_Recordset1['mn']; ?></td>
  68.       <td><?php echo $row_Recordset1['info']; ?></td>
  69.       <td><?php echo $row_Recordset1['img']; ?></td>
  70.     </tr>
  71.     <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  72. </table>
  73. </body>
  74. </html>
  75. <?php
  76. mysql_free_result($Recordset1);
  77. ?>

con funcion

Código php:
Ver original
  1. <?php require_once('../Connections/basbase.php'); ?>
  2. <?php
  3. function tab1(){
  4. if (!function_exists("GetSQLValueString")) {
  5. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  6. {
  7.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.  
  9.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  10.  
  11.   switch ($theType) {
  12.     case "text":
  13.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  14.       break;    
  15.     case "long":
  16.     case "int":
  17.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  18.       break;
  19.     case "double":
  20.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  21.       break;
  22.     case "date":
  23.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  24.       break;
  25.     case "defined":
  26.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  27.       break;
  28.   }
  29.   return $theValue;
  30. }
  31. }
  32.  
  33. mysql_select_db($database_basbase, $basbase);
  34. $query_Recordset1 = "SELECT * FROM list_movies";
  35. $Recordset1 = mysql_query($query_Recordset1, $basbase) or die(mysql_error());
  36. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  37. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  38. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  39. <html xmlns="http://www.w3.org/1999/xhtml">
  40. <head>
  41. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  42. <title>Documento sin t&iacute;tulo</title>
  43. </head>
  44.  
  45. <body>
  46. <table border="1">
  47.   <tr>
  48.     <td>ID</td>
  49.     <td>name_movie</td>
  50.     <td>lenguage</td>
  51.     <td>Sub</td>
  52.     <td>year</td>
  53.     <td>tipe</td>
  54.     <td>format</td>
  55.     <td>mn</td>
  56.     <td>info</td>
  57.     <td>img</td>
  58.   </tr>
  59.   <?php do { ?>
  60.     <tr>
  61.       <td><?php echo $row_Recordset1['ID']; ?></td>
  62.       <td><?php echo $row_Recordset1['name_movie']; ?></td>
  63.       <td><?php echo $row_Recordset1['lenguage']; ?></td>
  64.       <td><?php echo $row_Recordset1['Sub']; ?></td>
  65.       <td><?php echo $row_Recordset1['year']; ?></td>
  66.       <td><?php echo $row_Recordset1['tipe']; ?></td>
  67.       <td><?php echo $row_Recordset1['format']; ?></td>
  68.       <td><?php echo $row_Recordset1['mn']; ?></td>
  69.       <td><?php echo $row_Recordset1['info']; ?></td>
  70.       <td><?php echo $row_Recordset1['img']; ?></td>
  71.     </tr>
  72.     <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  73. </table>
  74. </body>
  75. </html>
  76. <?php
  77. mysql_free_result($Recordset1);
  78. ?><? } ?>
con global como ?:S
__________________
@ivancamiloGo
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 15:00.