PHP - Porfavor, array!

 
Vista:

Porfavor, array!

Publicado por Ismael (6 intervenciones) el 31/01/2008 19:15:02
Hola amigos porfavor no encuentro la solución a mi problema pasado, se los vuelvo a poner

while($row = mysql_fetch_array($result)) { $a[]=$row[0]; $b[]=$row[2];}

for($x=1; $x<2; $x++)
{
$menu = array
(

$a[$x] => array
(
'text' => $b[0],
'class' => 'articles',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 0
) ,
);

};

asi me marca un error en el array lo unico que quiero esque el $x se vaya aumentando en el array.... Espero me puedan ayudar Gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Porfavor, array!

Publicado por insignia (1 intervención) el 01/02/2008 10:18:22
En ese for no estás añadiendo valores e indices al array, sino que lo estas inicializando cada vez. Prueba así.

$menu=array();

for($x=1; $x<2; $x++)
{
$indice=$a[$x];
$menu[$indice] = array (
'text' => $b[0],
'class' => 'articles',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 0
);
};

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Porfavor, array!

Publicado por Ismael (6 intervenciones) el 01/02/2008 17:27:54
Hola Insignia, si entiendo lo que me dices, pero bueno no me funciona aun asi, lo que pasa esque yo baje un menu pero tu defines los padres e hijos, entonces ese lo estoy tratando de hacer con base de datos entonces te paso el original para que tengas una vision mas clara, y muchisimas gracias por tu ayuda..


<?php
/*
|---------------------------------------------------------------
| CREDITS
|---------------------------------------------------------------
|
| http://www.cssplay.co.uk/ for the best free css menus
| http://www.famfamfam.com/lab/icons/silk/ for the icons
|
*/
error_reporting ( E_ALL );

$menu = array
(
1 => array
(
'text' => 'Articles',
'class' => 'articles',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 0
),
2 => array
(
'text' => 'Users',
'class' => 'users',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 0
),
3 => array
(
'text' => 'Groups',
'class' => 'groups',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 0
),
4 => array
(
'text' => 'Settings',
'class' => 'settings',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 0
),
5 => array
(
'text' => 'Add new',
'class' => 'add_article',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 1
),
6 => array
(
'text' => 'Categories',
'class' => 'categories',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 1
),
7 => array
(
'text' => 'Add new',
'class' => 'add_user',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 2
),
8 => array
(
'text' => 'Delete',
'class' => 'delete',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 1
),
9 => array
(
'text' => 'Show',
'class' => 'show',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 2
),
10 => array
(
'text' => 'Last created',
'class' => 'last',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 9
),
11 => array
(
'text' => 'First created',
'class' => 'first',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 9
),
12 => array
(
'text' => 'All',
'class' => 'all',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 9
),
13 => array
(
'text' => 'None',
'class' => 'none',
'link' => '#',
'show_condition'=> TRUE,
'parent' => 9
)

);

function build_menu ( $menu )
{
$out = '<div class="container4">' . " ";
$out .= ' <div class="menu4">' . " ";
$out .= " ".'<ul>' . " ";

for ( $i = 1; $i <= count ( $menu ); $i++ )
{
if ( is_array ( $menu [ $i ] ) ) {//must be by construction but let's keep the errors home
if ( $menu [ $i ] [ 'show_condition' ] && $menu [ $i ] [ 'parent' ] == 0 ) {//are we allowed to see this menu?
$out .= '<li class="' . $menu [ $i ] [ 'class' ] . '"><a href="' . $menu [ $i ] [ 'link' ] . '">';
$out .= $menu [ $i ] [ 'text' ];
$out .= '</a>';
$out .= get_childs ( $menu, $i );
$out .= '</li>' . " ";
}
}
else {
die ( sprintf ( 'menu nr %s must be an array', $i ) );
}
}

$out .= '</ul>'." ";
$out .= " " . '</div>';
return $out . " " . '</div>';
}

function get_childs ( $menu, $el_id )
{
$has_subcats = FALSE;
$out = '';
$out .= " ".' <ul>' . " ";
for ( $i = 1; $i <= count ( $menu ); $i++ )
{
if ( $menu [ $i ] [ 'show_condition' ] && $menu [ $i ] [ 'parent' ] == $el_id ) {//are we allowed to see this menu?
$has_subcats = TRUE;
$add_class = ( get_childs ( $menu, $i ) != FALSE ) ? ' subsubl' : '';
$out .= ' <li class="' . $menu [ $i ] [ 'class' ] . $add_class . '"><a href="' . $menu [ $i ] [ 'link' ] . '">';
$out .= $menu [ $i ] [ 'text' ];
$out .= '</a>';
$out .= get_childs ( $menu, $i );
$out .= '</li>' . " ";
}
}
$out .= ' </ul>'." ";
return ( $has_subcats ) ? $out : FALSE;
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic PHP/CSS menu by roScripts</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div style="width:700px;margin:100px auto">
<h2>Dynamic PHP/CSS menu by <a href="http://www.roscripts.com" title="programming articles and tutorials" target="_blank">roScripts</a></h2>

<?= build_menu ( $menu ) ?>

</div>
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Porfavor, array! Solucionado!!

Publicado por Ismael (6 intervenciones) el 01/02/2008 19:29:16
Hola Insignia, muchas gracias por tu ayuda, ya quedo =)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar