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
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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.