php - while loop not ending as expected -


i might crazy here, pretty confused why while loop seems never end, causes page continuously load , chokes server several min afterwords.

basically have table of photo albums

+----+--------+--------+ | id | title  | parent | +----+--------+--------+ | 1  | album1 | 0      | +----+--------+--------+ | 2  | album2 | 0      | +----+--------+--------+ | 3  | album3 | 2      | +----+--------+--------+ | 4  | album4 | 3      | +----+--------+--------+ | 5  | album5 | 4      | +----+--------+--------+ | 6  | album6 | 1      | +----+--------+--------+ 

so have here hierarchy of albums this

- album1   ^- album6 - album2   ^- album3      ^- album4         ^- album5 

i have table of photos themselves

+----+--------+-------+--------+ | id | title  | album | master | +----+--------+-------+--------+ | 1  | photo1 | 1     | 1      | +----+--------+-------+--------+ | 2  | photo2 | 2     | 2      | +----+--------+-------+--------+ | 3  | photo3 | 6     | 1      | +----+--------+-------+--------+ | 4  | photo4 | 4     | 2      | +----+--------+-------+--------+ | 5  | photo5 | 5     | 2      | +----+--------+-------+--------+ | 6  | photo6 | 3     | 2      | +----+--------+-------+--------+ 

so can see have photos , belong each album, want able see master album belong to, or lowest possibly album.

i not want add col photo albums table says album master album. if must can try , without doing so.

to figured while loop.

so when add album via form current album id via hidden input field , tie $parent

$parent = $_post['album']; 

and since cannot add photos in root directory album id greater 1, if adding album 1, right $parent equal 1

so introduce while tag

while ($parent>0) { 

then album data $parent album database, yes have class setup , working, not believe issue works on own without while loop.

    $item = $mysql->get_data("photos_albums", $parent); 

then check see if parent of $parent album greater 0, not being root album

    if ($item['parent']>0) { 

if change $parent previous albums $parent , run again until album whos parent 0

        $parent = item['parent']; 

if not greater 0, know 0 , $parent album lowest possible album , master album one

    } else {         $master = $item['id'];     } } 

all of combines code, me not work, causes page continuously load.

$parent = $_post['album']; $master = 0;  while ($parent>0)     $item = $mysql->get_data("photos_albums", $parent);     if ($item['parent']>0) {         $parent = $item['parent'];     } else {         $master = $item['id'];     } } 

am missing something?

parent reset when parent higher 0

if ($item['parent']>0) {     $parent = $item['parent']; } else {     $master = $item['id'];     $parent = 0; } 

should fix


Popular posts from this blog