Jump to content

sorting our an array


carlosx2

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.