|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
dynamic array population
What's going on? Why won't this thing work? Can someone point out the error in this script? It fails on the lines where the $array1 array is used. Help!
<?php require("../includes/header.php"); ?> <center> <title>script archive</title> <table border=1 width=70%> <td width=100% bgcolor="white"><font color="navy" face="Arial, Helvetica" size=2 border=0> <center> <table border=0 width=100%><td bgcolor="black"> <font color="silver" face="Arial, Helvetica" size=1 border=0><center> <b>copyright info, blah blah blah <br> </b> </table> <p> <center><strong> <?php $handle=opendir('./code/'); $array1=array(); echo "Available Scripts:<p>"; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php") { //add each file to an array so I can sort foreach ( $file as $codefile ) { $array1[] = $codefile; } } closedir($handle); } //sort results of new array $sortedarray = sort($array1); //one last foreach loop, this time to display results of new array foreach ( $sortedarray as $showcode ) { echo "<a href=display.php?file=$showcode>"; $filename = (str_replace("_"," ",$showcode)); $filename = (str_replace(".","(",$showcode)); echo $filename .")</a><br>n"; } ?> <p> </strong> </td> </table> <?php include("./includes/footer.php"); ?> |
|
#2
|
|||||
|
|||||
|
RE: dynamic array population
Here you go, give this a try:
php Code:
Let me know how that goes.... |
|
#3
|
|||
|
|||
|
RE: dynamic array population
Yes! It worked! I used the following script and it solved my problem, but I like the one you posted better since it was mostly my code (not lifted from someone else's page!) Thanks!
/************************8/ // populate array $array_count = 0; $songs = array(); //open dir $handle=opendir('./code/'); echo "Available Scripts:<p>"; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php" && $file != "index2.php") { $songs[$array_count]["filename"] = $file; $array_count++; } } closedir($handle); //sort results of new array sort($songs); // output array for ($i = 0; $i < $array_count; $i++) { $showcode = $songs[$i]["filename"]; echo "<a href=display.php?file=$showcode>"; $var = (str_replace("_"," ",$showcode)); $var = (str_replace("."," (",$var)); echo $var .")</a><br>n"; } |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > dynamic array population |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|