Jump to content

Problem looping sql result


wepnop

Recommended Posts

	echo 'RES:' . mysql_num_rows($res);
while ($row = mysql_fetch_assoc($res)) {
	echo 'test';
}

 

The sql consult for this is: SELECT * FROM `cateogories` and it goes ok. In mysql admin i see 5 entries, but that code only echoes test 3 times.

Textos parciales
Textos completos
Show binary contents
Show BLOB contents
Ocultar Transformación del navegador
ID 	Cantidad 	Tecnologia 	Tipo Conexion 	Capacidad
Editar 	Borrar 	15 	11 	JB SUCKS 	DDR 	128
Editar 	Borrar 	14 	11 	JB SUCKS 	DDR 	128
Editar 	Borrar 	13 	11 	JB SUCKS 	DDR 	128
Editar 	Borrar 	12 	1 	wep 	wep 	322
Editar 	Borrar 	11 	1 	wep 	wep 	32

 

Its in spanish but well..

 

These is the rows that are echoed:

ID 	 Cantidad 	 Tipo	 Tecnologia	 Capacidad
13	11	JB SUCKS	DDR	128
12	1	wep	wep	322
11	1	wep	wep	32

Link to comment
https://forums.phpfreaks.com/topic/236562-problem-looping-sql-result/
Share on other sites

If you post all the relevant code, starting with the mysql_query() statement, through to the } on the end of your while(){} loop, someone can probably help with what your code is doing.

 

	
    $consulta = 'SELECT * FROM `' . $categorias[$clave]['nombre_sql'] . '` ' ;

$res = consultar_bd($consulta, true);

echo 'RES:' . mysql_num_rows($res);

 

Note that now it echoes 4, i have deleted this line while testing:

 

$tmp = mysql_fetch_assoc($res);

It was just after the consultar_bd function, that calls mysql_query

 

Somewhere else in your code (could be in your consultar_bd() function), you have a mysql_fetch_assoc($res); or other mysql_fetch_xxxxx() statement or you are overwriting the $res variable.

 

Without seeing the requested code, it's not possible to do more than guess what your code is doing wrong.

Somewhere else in your code (could be in your consultar_bd() function), you have a mysql_fetch_assoc($res); or other mysql_fetch_xxxxx() statement or you are overwriting the $res variable.

 

Without seeing the requested code, it's not possible to do more than guess what your code is doing wrong.

 

If i use the mysql_data_seek($res, 0); it goes well. Yes, in consultar_bd i fetch the object if the result is true to test if is empty or not (i use my own error system that calls for that). I added a data seek to the 0 after the fetch and now it goes well.

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.