Buenas,
Hace un rato escribí un post que le pido a los moderadores que lo borren ya que está desactualizado y al final puede confundir más que explicarme como quiero.
La cuestión es que me han mandado a hacer un trabajo en clases de una especie de multinivel de 5 niveles.
Tengo el siguiente código:
Código PHP:
<?php
$conexion = mysql_connect('localhost', 'root', '');
mysql_select_db('testing', $conexion);
function get_tree($id, $level = 5)
{
$result = mysql_query('SELECT id, title FROM testing WHERE parent_id='.$id) ;
while ($row = mysql_fetch_array($result))
{
echo str_repeat(' ', $level), $row['title'], "\r\n";
get_tree($row['id'], $level + 1);
}
}
call_user_func('get_tree', $id = 1);
?>
Y la base de datos es la siguiente:
Código HTML:
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
CREATE TABLE IF NOT EXISTS `testing` (
`id` int(120) NOT NULL,
`title` varchar(120) NOT NULL,
`parent_id` int(120) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
--
-- Volcado de datos para la tabla `testing`
--
INSERT INTO `testing` (`id`, `title`, `parent_id`) VALUES
(1, 'UsuarioA', 0),
(2, 'UsuarioB', 1),
(3, 'UsuarioC', 2),
(4, 'UsuarioE', 3),
(5, 'UsuarioD', 4),
(6, 'UsuarioF', 5),
(7, 'UsuarioG', 6);
--
-- Índices para tablas volcadas
--
--
-- Indices de la tabla `testing`
--
ALTER TABLE `testing`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT de las tablas volcadas
--
--
-- AUTO_INCREMENT de la tabla `testing`
--
ALTER TABLE `testing`
MODIFY `id` int(120) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=8;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Cómo podéis ver sigue lanzándome más usuarios sobrepasando el 5º nivel, cómo podría hacer que al llegar al nivel 5 parase?
Muchas gracias por la ayuda de antemano,
Salu2!