How to split files from array

Started on the old forum in April 2011 · view the original in the archive · old links redirect here

10 replies · 759 views · started 15 years ago · 1 min read

2 participants
poporopop25 Developer · 60 posts #1
<?php
$cats=array(
"turn the beat on-beat production.mp3"=>"turn the beat on-beat production",
"the final destiny-virus.mp3"=>"the final destiny-virus",
"the access of trance-dj crack.mp3"=>"the access of trance-dj crack",
"star wars theme-plan @ work.mp3"=>"star wars theme-plan @ work",
"secret desire-steven gore.mp3"=>"secret desire-steven gore",
"paradise-t.o..mp3"=>"paradise-t.o.",
"out of sight-copycat.mp3"=>"out of sight-copycat",
"my definition of trance-lord razor.mp3"=>"my definition of trance-lord razor",
"magic melody-groove solution.mp3"=>"magic melody-groove solution",
"god danced-dj taylor & flow.mp3"=>"god danced-dj taylor & flow",
);
shuffle($cats);
foreach($cats as $key=>$cat){
$lnk="<b>» </b><a href=\"file.php?file=Club/$key&start=1\">$cat</a><br/>";
echo $lnk;
}
?>

DISPLAY: Club » my definition of trance-lord razor » magic melody-groove solution » god danced-dj taylor & flow » star wars theme-plan @ work » secret desire-steven gore » the access of trance-dj crack » the final destiny-virus » turn the beat on-beat production » paradise-t.o. » out of sight-copycat

HELP ME... I NEED TO DISPLAY 5 LINKS ONLY...

something else Fellow · 2,296 posts #2
$n=0;
shuffle($cats); 
foreach($cats as $key=>$cat){ 
$lnk="<b>» </b><a href=\"file.php?file=Club/$key&start=1\">$cat</a><br/>"; 
echo $lnk; 
$n++;
if($n==5)
break;
}
poporopop25 Developer · 60 posts #4

sir is there a script that can autoindex this type of array? in short to have a pagination... there will be no problem on sorting from new to old i just not to insert that shuffle(); thing... my only problem is how to split the total output into 5 and having a pagination...

something else Fellow · 2,296 posts #5
<?php 
$amount = 5;
$page = (int)$_GET['page'];
if(!isset($page)||$page<1) $page = 1;
$limit = $page * $amount;
$cats=array( 
"turn the beat on-beat production.mp3"=>"turn the beat on-beat production", 
"the final destiny-virus.mp3"=>"the final destiny-virus", 
"the access of trance-dj crack.mp3"=>"the access of trance-dj crack", 
"star wars theme-plan @ work.mp3"=>"star wars theme-plan @ work", 
"secret desire-steven gore.mp3"=>"secret desire-steven gore", 
"paradise-t.o..mp3"=>"paradise-t.o.", 
"out of sight-copycat.mp3"=>"out of sight-copycat", 
"my definition of trance-lord razor.mp3"=>"my definition of trance-lord razor", 
"magic melody-groove solution.mp3"=>"magic melody-groove solution", 
"god danced-dj taylor & flow.mp3"=>"god danced-dj taylor & flow"); 
$total = count($cats);
if($limit>$total) $limit = $total;
foreach(array_slice($cats, $limit-$amount, $amount) as $key=>$cat){ 
echo "<b>» </b><a href=\"file.php?file=Club/$key&start=1\">$cat</a><br/>"; 
} 
$pagelimit = ceil($total/$amount);
echo '<a href="'.$_SERVER['PHP_SELF'].'">1 </a>';
if($page>2)
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($page-1).'">'.($page-1).' </a>';
if((($total/$amount)>$page)&&($page!=($pagelimit-1)))
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($page+1).'">'.($page+1).' </a>';
if($pagelimit>1)
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$pagelimit.'">'.$pagelimit.' </a>';
?>
something else Fellow · 2,296 posts #9

you dont have to use the key if the cat is the same (just missing .mp3) eg:

echo '<b>» </b><a href="file.php?file=Club/'.$cat.'.mp3&start=1">'.$cat.'</a><br/>'; 
poporopop25 Developer · 60 posts #10

yeah $cat has no .mp3 thats why im using this function cause i don't want the .mp3 to be appeared.. anyway tnx for the response since im using autoindex here im going to use $cat with .mp3 on url.

poporopop25 Developer · 60 posts #11

i'm having a difficult to fix the wrong output using this code.. ex. i have total files of 31 when you view the last page you should see only one link to display but its not you will see 10 links, the 9 links displayed were repeated from the previous page but the last link is the correct link to displayed on page 3...

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close