carlosx2 Posted October 9, 2009 Share Posted October 9, 2009 OK i have traded one solution for another problem. after a long search on the web i give up. i need some help here. <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo '<link href="path/style.css" rel="stylesheet" type="text/css">'; $model = $_GET['id']; $id = 1; $modelname = split(':', $model); $movie = glob("path/*.jpg"); ?> <div class="table1"> <?php foreach ($movie as $file){ if($id <= 6){ echo "save movie <a href='$file'>part: $id</a><br />"; $id++; } } ?> </div> <div class="space"> </div> <div class="table2"> <?php foreach ($movie as $file){ if($id >= 7){ echo "save movie <a href='$file'>part: $id</a><br />"; $id++; } } ?> </div> </body> </html> What i need to do here as i have the following problem. i have my div's and each div has to hold a number of download files, like ( 1 to 6 and the second div has to hold 7 to 12) but now that i have figured out the styling i have the problem that when i say count from 1 to 6 its hold file number 1 to 6 but then in the second div it start at number 6 but that actual linked file is number 1 so i have a repeat of my link . I know what my array hold all the files, that i know. but i have no idea how i can restrict the echo to only print 1 to 5 and second echo to print 6 to 12 and third div 13 to 16 and so on. How would i do that without changing the structure of my divs. Hope some one can help me a bit. Btw do learn a lot of this forum. thanks to every one. Php is pretty hard when you don't know where to look for the right solution. Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/ Share on other sites More sharing options...
carlosx2 Posted October 9, 2009 Author Share Posted October 9, 2009 hope some can help me. its late here so i will be off to bed. i will checkin tomorrow. Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/#findComment-933449 Share on other sites More sharing options...
carlosx2 Posted October 9, 2009 Author Share Posted October 9, 2009 nobody who can help me? Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/#findComment-933612 Share on other sites More sharing options...
ameyemad Posted October 9, 2009 Share Posted October 9, 2009 this all should get done within 1 loop... hope this helps... foreach ($movie as $file){ if($id <= 6){ echo "save movie <a href='$file'>part: $id</a><br />"; } else if ($id>=7){ if (!$_div1){ echo '</div><div class="space"> </div><div class="table2">'; $_div1=1; } echo "save movie <a href='$file'>part: $id</a><br />"; } $id++; } Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/#findComment-933613 Share on other sites More sharing options...
carlosx2 Posted October 9, 2009 Author Share Posted October 9, 2009 ok just for learning purpose what does this part mean. I have seen the ! a lot. and if i am right it would be the negative way of a function like do not or something. am i correct. else if ($id>=7){ if (!$_div1){ echo '</div><div class="space"> </div><div class="table2">'; $_div1=1; not sure what this exactly doe . if you can tell it would help understand what i am really doing here and teach me even more. thanks Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/#findComment-933615 Share on other sites More sharing options...
ameyemad Posted October 9, 2009 Share Posted October 9, 2009 basically it means if not found. as you can see i have !$_div1, so it's telling the script that if $_div1 has not been identified as yet, do something. After I get it to do what I want it to do, I identify the variable by adding $_div1=1; Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/#findComment-933620 Share on other sites More sharing options...
carlosx2 Posted October 9, 2009 Author Share Posted October 9, 2009 thanks buti still have one question. $_div1=1; is there to stop from printing out the echo more then once or what. it still a bit fussy for me. sorry. Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/#findComment-933661 Share on other sites More sharing options...
carlosx2 Posted October 9, 2009 Author Share Posted October 9, 2009 i have figured it out. thanks Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/#findComment-933671 Share on other sites More sharing options...
ameyemad Posted October 9, 2009 Share Posted October 9, 2009 good luck Link to comment https://forums.phpfreaks.com/topic/177037-sorting-our-an-array/#findComment-933674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.