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
 
Unread Codewalkers Forums Sponsor:
  #1  
Old March 20th, 2002, 09: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: 3
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, 10:45 PM
Matt Matt is offline
Contributing User
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 12 m 16 sec
Reputation Power: 7
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, 10: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: 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";
}

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!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek