¿Alguien me podría decir dónde está el error? :(

  • Autor Autor Jackass89
  • Fecha de inicio Fecha de inicio
J

Jackass89

Beta
Programador
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Betas!!, estoy haciendo unas pruebitas sobre paginación y me encuentro con lo siguiente:

Insertar CODE, HTML o PHP:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\web\p\getdata.php on line 8

el archivo getdata.php es:
Insertar CODE, HTML o PHP:
<?php
include 'library.php'; // include the library file
session_start();
if(isset($_POST["lastid"]) && $_POST["lastid"] != "0"){
	$lastid = $_POST["lastid"]; // save the posted value in a variable
	if($_SESSION["lastid"] != $_POST["lastid"]) { // Check session for avoid duplicate records
		$country_select = mysql_query("SELECT * FROM 'countries' WHERE country_id < '$lastid' ORDER BY country_id DESC LIMIT 5");
		if(mysql_num_rows($country_select) > 0){
			$last_id = '';
			while($fetch = mysql_fetch_array($country_select)){
			?>
			<div class="as_country_container" id="<?php echo $fetch['country_id']; ?>">
				<table>
				<tr>
					<td style="width:300px;"><?php echo $fetch["country_name"]; ?></td>
					<td><img src="country_flags/<?php echo $fetch["country_code"]; ?>.png" alt="<?php echo $fetch["country_code"]; ?>" title="<?php echo $fetch["country_code"]; ?>" /></td>
				</tr>
				</table>
			</div>
		<?php
			$last_id = $fetch["country_id"];
			}
			$_SESSION['lastid'] = $lastid; // Create session for check and avoid dupilicate records
		}
	}
}
?>


Llevo rato buscando y no encuentro nada.
¿Alguien me podría decir cual es el error? XD
 
PHP:
$country_select = mysql_query("SELECT * FROM 'countries' WHERE country_id < '".$lastid."' ORDER BY country_id DESC LIMIT 5");
Linea 8
 
PHP:
$country_select = mysql_query("SELECT * FROM 'countries' WHERE country_id < '".$lastid."' ORDER BY country_id DESC LIMIT 5");
Linea 8

Si, es esa, pero no me doy cuenta cual es el error :/
 
Reemplaza con lo que puse yo

El código me quedo así:
Insertar CODE, HTML o PHP:
<?php
include 'library.php'; // include the library file
session_start();
if(isset($_POST["lastid"]) && $_POST["lastid"] != "0"){
	$lastid = $_POST["lastid"]; // save the posted value in a variable
	if($_SESSION["lastid"] != $_POST["lastid"]) { // Check session for avoid duplicate records
$country_select = mysql_query("SELECT * FROM 'countries' WHERE country_id < "'.$lastid.'" ORDER BY country_id DESC LIMIT 5"); 
		if(mysql_num_rows($country_select) > 0){
			$last_id = '';
			while($fetch = mysql_fetch_array($country_select)){
			?>
			<div class="as_country_container" id="<?php echo $fetch['country_id']; ?>">
				<table>
				<tr>
					<td style="width:300px;"><?php echo $fetch["country_name"]; ?></td>
					<td><img src="country_flags/<?php echo $fetch["country_code"]; ?>.png" alt="<?php echo $fetch["country_code"]; ?>" title="<?php echo $fetch["country_code"]; ?>" /></td>
				</tr>
				</table>
			</div>
		<?php
			$last_id = $fetch["country_id"];
			}
			$_SESSION['lastid'] = $lastid; // Create session for check and avoid dupilicate records
		}
	}
}
?>

pero me sigue apareciendo el mismo error 🙁
 
no reemplazaste bien tenes las comillas al revez
PHP:
$country_select = mysql_query("SELECT * FROM 'countries' WHERE country_id < '".$lastid."' ORDER BY country_id DESC LIMIT 5");
:encouragement:
 
no reemplazaste bien tenes las comillas al revez
PHP:
$country_select = mysql_query("SELECT * FROM 'countries' WHERE country_id < '".$lastid."' ORDER BY country_id DESC LIMIT 5");
:encouragement:

Listo, ya lo corregí!, pero ahor me dice que hay error en:
Insertar CODE, HTML o PHP:
if (mysql_num_rows($country_id) > 0)
No salgo de una que me meto en otra XD
 
Listo, ya lo corregí!, pero ahor me dice que hay error en:
Insertar CODE, HTML o PHP:
if (mysql_num_rows($country_id) > 0)
No salgo de una que me meto en otra XD
Cual es el nuevo error? capaz te devuelve un boolean la query.. (un false)
Proba con
Insertar CODE, HTML o PHP:
if (mysql_num_rows((int) $country_id) > 0)
 
¡¡Problema solucionado!!, muchísimas gracias 😀
 
Atrás
Arriba