PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old March 20th, 2002, 08:25 PM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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"); ?>

Reply With Quote
  #2  
Old March 20th, 2002, 09:45 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 23 sec
Reputation Power: 6
RE: dynamic array population

Here you go, give this a try:

php Code:
Original - php Code
  1.  
  2. <?php require("../includes/header.php"); ?>
  3.  
  4. <center>
  5. <title>script archive</title>
  6. <table border=1 width=70%>
  7. <td width=100% bgcolor="white"><font color="navy" face="Arial, Helvetica" size=2 border=0>
  8. <center>
  9. <table border=0 width=100%><td bgcolor="black">
  10. <font color="silver" face="Arial, Helvetica" size=1 border=0><center>
  11. <b>copyright info, blah blah blah <br>
  12. </b>
  13. </table>
  14. <p>
  15. <center><strong>
  16. <?php
  17.  
  18. $handle = opendir('.') or die('Unable to open dir.');
  19. $array1 = array();
  20. echo "Available Scripts:<p>";
  21. while (false !== ($file = readdir($handle))) {
  22.     if ($file != "." && $file != ".." && $file != "index.php") {
  23.         //add each file to an array so I can sort
  24.         $array1[] = $file;
  25.     }
  26. }
  27. closedir($handle);
  28.  
  29. //sort results of new array
  30. $sortedarray = $array1;
  31. sort($sortedarray);
  32.  
  33. //one last foreach loop, this time to display results of new array
  34. foreach ( $sortedarray as $showcode ) {
  35.     echo "<a href=display.php?file=$showcode>";
  36.     $filename = (str_replace("_"," ",$showcode));
  37.     $filename = (str_replace(".","(",$showcode));
  38.     echo $filename .")</a><br>n";
  39. }
  40.  
  41. ?>
  42. <p>
  43. </strong>
  44. </td>
  45. </table>
  46. <?php include("./includes/footer.php"); ?> 


Let me know how that goes....

Reply With Quote
  #3  
Old March 20th, 2002, 09:56 PM
sethadam1 sethadam1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Orlando, FL
Posts: 223 sethadam1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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";
}

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > dynamic array population


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway