wepnop Posted May 16, 2011 Share Posted May 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236562-problem-looping-sql-result/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2011 Share Posted May 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236562-problem-looping-sql-result/#findComment-1216103 Share on other sites More sharing options...
wepnop Posted May 16, 2011 Author Share Posted May 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236562-problem-looping-sql-result/#findComment-1216105 Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2011 Share Posted May 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236562-problem-looping-sql-result/#findComment-1216108 Share on other sites More sharing options...
wepnop Posted May 16, 2011 Author Share Posted May 16, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/236562-problem-looping-sql-result/#findComment-1216109 Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2011 Share Posted May 16, 2011 i fetch the object if the result is true to test if is empty or not ^^^ That's what they made mysql_num_rows for. Quote Link to comment https://forums.phpfreaks.com/topic/236562-problem-looping-sql-result/#findComment-1216110 Share on other sites More sharing options...
wepnop Posted May 16, 2011 Author Share Posted May 16, 2011 Thanks again, its better that function. Quote Link to comment https://forums.phpfreaks.com/topic/236562-problem-looping-sql-result/#findComment-1216120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.