Lautarox Posted June 9, 2008 Share Posted June 9, 2008 I got this clase to show the list <? class pages extends mysql { function load () { $activated = 1; $query = "SELECT page, link FROM pages WHERE activated = '$activated' ORDER BY posicion"; parent::connect(); $resultado = parent::query($query); $arr = parent::arr($resultado); echo '<ul>'; foreach ($arr as $items) { echo '<li><a href="'.$items['link'].'">'.$items['page'].'</a></li>'; } echo '</ul>'; } } ?> This are the other functions used in the class <? function query ($query) { $resultado = mysql_query($query); $test = mysql_num_rows($resultado); if ($test = 0) { echo 'Error en peticion mysql'; } else { return $resultado; } } function arr ($resultado) { $arr = mysql_fetch_array($resultado); $test = array_count_values($arr); if ($test = 0) { echo 'El array no tiene valores'; } else { return $arr; } } ?> And it just prints this <ul><li><a href="H">H</a></li><li><a href="H">H</a></li><li><a href="?">?</a></li><li><a href="?">?</a></li></ul> Is it a database table data type error? Quote Link to comment https://forums.phpfreaks.com/topic/109458-solved-problem-creating-menu-list/ Share on other sites More sharing options...
irvieto Posted June 10, 2008 Share Posted June 10, 2008 Cuidado...Carefull if ($test = 0) { //$test == 0 <--Esto es lo correcto. echo 'Error en peticion mysql'; } También hay que revisar el foreach. <?php /* El valor de $arr luego de obtener el resultado con fetch_array es un array asociativo.... no hay necesidad de un foreach. $arr = array( 'page' =>'algun valor..', 'link' => 'otro valor' ); Al ejecutar el foreach, $items obtiene el valor: */ foreach ($arr as $items){ //$items = 'algun valor..'; <-- } ## # Usted ocupa algo como lo siguiente... ## while( $arr = mysql_fetch_array($resultado) ){ echo '<li><a href="'.$arr['link'].'">'.$arr['page'].'</a></li>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109458-solved-problem-creating-menu-list/#findComment-561819 Share on other sites More sharing options...
Lautarox Posted June 10, 2008 Author Share Posted June 10, 2008 Mmm the foreach was the error here, i have replaced it with the while, and i have corrected the if error too, thanks! =P / Mmm el foreach era el error creo.., lo reemplaze con el while y andubo bastante bien, tambien corregi el error del if, gracias Quote Link to comment https://forums.phpfreaks.com/topic/109458-solved-problem-creating-menu-list/#findComment-562193 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.