Foros del Web » Programando para Internet » PHP »

Ayudenme con mi problema porfavor

Estas en el tema de Ayudenme con mi problema porfavor en el foro de PHP en Foros del Web. Bueno noce cual es mi error que me sale esto: Código: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a1300228/public_html/noticias.php on ...
  #1 (permalink)  
Antiguo 27/01/2009, 09:20
 
Fecha de Ingreso: octubre-2008
Mensajes: 155
Antigüedad: 15 años, 6 meses
Puntos: 1
Ayudenme con mi problema porfavor

Bueno noce cual es mi error que me sale esto:
Código:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a1300228/public_html/noticias.php on line 67
y la linea es esta:

Código:
While ($reg = mysql_fetch_assoc($result)) {
aqui les dejo todo el codigo:

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>


  <title>Noticias</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>

<?php
// primero se conecta a la base de datos:
require 'conexion_mysql.php';
// creamos la consulta SQL. Esta consulta muestra TODOS los registros de la tabla "users":
$sqltabla="create temporary table `tempUsuarios` (

  `ID` int(11) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `alias` varchar(255) NOT NULL default '',
  `title_alias` varchar(255) NOT NULL default '',
  `introtext` mediumtext NOT NULL,
  `fulltext` mediumtext NOT NULL,
  `state` tinyint(3) NOT NULL default '0',
  `sectionid` int(11) unsigned NOT NULL default '0',
  `mask` int(11) unsigned NOT NULL default '0',
  `catid` int(11) unsigned NOT NULL default '0',
  `created` datetime NOT NULL default '0000-00-00 00:00:00',
  `created_by` int(11) unsigned NOT NULL default '0',
  `created_by_alias` varchar(255) NOT NULL default '',
  `modified` datetime NOT NULL default '0000-00-00 00:00:00',
  `modified_by` int(11) unsigned NOT NULL default '0',
  `checked_out` int(11) unsigned NOT NULL default '0',
  `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
  `publish_up` datetime NOT NULL default '0000-00-00 00:00:00',
  `publish_down` datetime NOT NULL default '0000-00-00 00:00:00',
  `images` text NOT NULL,
  `urls` text NOT NULL,
  `attribs` text NOT NULL,
  `version` int(11) unsigned NOT NULL default '1',
  `parentid` int(11) unsigned NOT NULL default '0',
  `ordering` int(11) NOT NULL default '0',
  `metakey` text NOT NULL,
  `metadesc` text NOT NULL,
  `access` int(11) unsigned NOT NULL default '0',
  `hits` int(11) unsigned NOT NULL default '0',
  `metadata` text NOT NULL,
  PRIMARY KEY  (`ID`),
  KEY `idx_section` (`sectionid`),
  KEY `idx_access` (`access`),
  KEY `idx_checkout` (`checked_out`),
  KEY `idx_state` (`state`),
  KEY `idx_catid` (`catid`),
  KEY `idx_createdby` (`created_by`)

)";
$consulta1 = "insert into tempUsuarios select * from noticias limit 4,4";
$consulta = "select * from tempUsuarios order by rand() limit 1";
// la ejecutamos
$result = mysql_query($consulta);
?>
<table border="1">
<tr>
<th>pagína de noticias</th>
</tr>
<?php
While ($reg = mysql_fetch_assoc($result)) {
// en cada iteracion el array $reg va a contener un nuevo registro que cumpla las condiciones; se accede a los datos usando el nombre del campo como indice
?>
<!--por cada iteracion se crea una fila nueva con los datos de los campos correspondientes-->
<tr>
<td><?php echo $reg['introtext'] ?></td>
</tr>
<?php
}
?>
</table>

</body>
</html>
espero que me puedan ayudar gracias
  #2 (permalink)  
Antiguo 27/01/2009, 09:25
 
Fecha de Ingreso: diciembre-2008
Mensajes: 454
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: Ayudenme con mi problema porfavor

te recomiendo que primero cree lata tabla y verifica si la tabla se crea correctamente
  #3 (permalink)  
Antiguo 27/01/2009, 09:36
Avatar de dART  
Fecha de Ingreso: enero-2009
Ubicación: Madrid
Mensajes: 246
Antigüedad: 15 años, 2 meses
Puntos: 7
Respuesta: Ayudenme con mi problema porfavor

Hola,

Antes que nada, una vez crees la base de datos (temporal o no) tienes que seleccionarla con
Código PHP:
mysql_select_db 
¿Lo has hecho ya?
  #4 (permalink)  
Antiguo 27/01/2009, 09:45
 
Fecha de Ingreso: octubre-2008
Mensajes: 155
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: Ayudenme con mi problema porfavor

Si ya lo he hecho esta en la linea 14:
Código:
require 'conexion_mysql.php';
  #5 (permalink)  
Antiguo 27/01/2009, 09:57
Avatar de dART  
Fecha de Ingreso: enero-2009
Ubicación: Madrid
Mensajes: 246
Antigüedad: 15 años, 2 meses
Puntos: 7
Respuesta: Ayudenme con mi problema porfavor

Hola,

Hagamos una cosa para ver bien el error. Cambia ésto (y todo lo demás de abajo)

Código PHP:
<?php

  
While ($reg mysql_fetch_assoc($result)){ 

?>
.. por ésto otro:

Código PHP:
<?php

   
if(!$result){
      echo 
"Error: $sql - " mysql_error(); 
      exit; 
   }

?>
Así conoceremos bien qué sucede realmente en la SQL.
  #6 (permalink)  
Antiguo 27/01/2009, 10:12
 
Fecha de Ingreso: octubre-2008
Mensajes: 155
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: Ayudenme con mi problema porfavor

Esto es lo que sale:

Código:
Error: - Table 'a1300228_users.tempUsuarios' doesn't exist
  #7 (permalink)  
Antiguo 27/01/2009, 10:25
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: Ayudenme con mi problema porfavor

Pues, el error es bien claro. La tabla en la cual estas tratando de insertar los datos no existe.
  #8 (permalink)  
Antiguo 27/01/2009, 11:01
 
Fecha de Ingreso: octubre-2008
Mensajes: 155
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: Ayudenme con mi problema porfavor

Si, Gracias a todos por ayudarme especialmente a d-ART, pero no funciona como uviera querido que funcione.
Lo que yo queria era que en una tabla que se llama noticias se sustrallera las ultimas 4 noticias y que por el create temporary table `newnoticias` tuviera las ultimas 4 noticias y que por aleatoriamente se sustrallera una noticia de las ultimas 4 noticias y no pasa eso.
aqui dejo mi nuevo codigo:
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>


  <title>Noticias</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>

<?php
// primero se conecta a la base de datos:
require 'conexion.php';
// creamos la consulta SQL. Esta consulta muestra TODOS los registros de la tabla "users":
$sqltabla="create temporary table `newnoticias` (

  `ID` int(11) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `alias` varchar(255) NOT NULL default '',
  `title_alias` varchar(255) NOT NULL default '',
  `introtext` mediumtext NOT NULL,
  `fulltext` mediumtext NOT NULL,
  `state` tinyint(3) NOT NULL default '0',
  `sectionid` int(11) unsigned NOT NULL default '0',
  `mask` int(11) unsigned NOT NULL default '0',
  `catid` int(11) unsigned NOT NULL default '0',
  `created` datetime NOT NULL default '0000-00-00 00:00:00',
  `created_by` int(11) unsigned NOT NULL default '0',
  `created_by_alias` varchar(255) NOT NULL default '',
  `modified` datetime NOT NULL default '0000-00-00 00:00:00',
  `modified_by` int(11) unsigned NOT NULL default '0',
  `checked_out` int(11) unsigned NOT NULL default '0',
  `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
  `publish_up` datetime NOT NULL default '0000-00-00 00:00:00',
  `publish_down` datetime NOT NULL default '0000-00-00 00:00:00',
  `images` text NOT NULL,
  `urls` text NOT NULL,
  `attribs` text NOT NULL,
  `version` int(11) unsigned NOT NULL default '1',
  `parentid` int(11) unsigned NOT NULL default '0',
  `ordering` int(11) NOT NULL default '0',
  `metakey` text NOT NULL,
  `metadesc` text NOT NULL,
  `access` int(11) unsigned NOT NULL default '0',
  `hits` int(11) unsigned NOT NULL default '0',
  `metadata` text NOT NULL,
  PRIMARY KEY  (`ID`),
  KEY `idx_section` (`sectionid`),
  KEY `idx_access` (`access`),
  KEY `idx_checkout` (`checked_out`),
  KEY `idx_state` (`state`),
  KEY `idx_catid` (`catid`),
  KEY `idx_createdby` (`created_by`)

)";
$consulta1 = "insert into newnoticias select * from noticias limit 4,4";
$consulta = "select * from newnoticias order by rand() limit 1";
// la ejecutamos
$result = mysql_query($consulta);
?>
<table border="1">
<tr>
<th>pagína de noticias</th>
</tr>
<?php
While ($reg = mysql_fetch_assoc($result)) {
// en cada iteracion el array $reg va a contener un nuevo registro que cumpla las condiciones; se accede a los datos usando el nombre del campo como indice
?>
<!--por cada iteracion se crea una fila nueva con los datos de los campos correspondientes-->
<tr>
<td><?php echo $reg['introtext'] ?></td>
</tr>
<?php
}
?>
</table>

</body>
</html>
  #9 (permalink)  
Antiguo 27/01/2009, 11:22
 
Fecha de Ingreso: octubre-2008
Mensajes: 155
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: Ayudenme con mi problema porfavor

Bueno ya solucione mi problema, la linea
Código:
$consulta1 = "insert into newnoticias select * from noticias limit 4,4";
lo cambien por esto:

Código:
$consulta1 = mysql_query ("insert into newnoticias SELECT * FROM noticias order by id desc limit 4");
  #10 (permalink)  
Antiguo 27/01/2009, 11:27
Avatar de dART  
Fecha de Ingreso: enero-2009
Ubicación: Madrid
Mensajes: 246
Antigüedad: 15 años, 2 meses
Puntos: 7
Respuesta: Ayudenme con mi problema porfavor

Hola,

¿Entonces, todo bien? ¿Se solucionó?
  #11 (permalink)  
Antiguo 27/01/2009, 12:24
 
Fecha de Ingreso: octubre-2008
Mensajes: 155
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: Ayudenme con mi problema porfavor

Si, Gracias.
  #12 (permalink)  
Antiguo 27/01/2009, 13:11
 
Fecha de Ingreso: enero-2009
Mensajes: 1
Antigüedad: 15 años, 2 meses
Puntos: 0
Información Respuesta: Ayudenme con mi problema porfavor

Me parece que no estaría de más que intentases usar una librería de tercera parte para manejar el Mysql desde el PHP.. te sugiero el ezSQL
  #13 (permalink)  
Antiguo 28/01/2009, 15:33
 
Fecha de Ingreso: octubre-2008
Mensajes: 155
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: Ayudenme con mi problema porfavor

Gracias por la sugerencia.
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 03:31.