Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-22-2004, 12:50 AM   PM User | #1
Raraken
Regular Coder

 
Join Date: Jan 2004
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Raraken is an unknown quantity at this point
an odd array problem

I never used to work with array's (That's why I know so little about them), but, anyway, I have an array, and its first 2 values are always blank.

How would I correct this?

My code:
PHP Code:
<?php
// This code is going to allow you to upload comics, and have the computer orginize them.
//lets set some array's to start off.
$file = array();
$strip = array();
if (
$handle opendir('comics/')) {
   while (
false !== ($file readdir($handle))) { 
       
$strip[] = $file;
   }
   
closedir($handle); 
}
// now, were going to run these actions for every comic, to format them to a proper array.

for ($looping=count($strip); $looping 0$looping --) {
  
//first thing to target: The comic's filename.
  
$filename $strip[$looping]; 
  
//now, were going to set "Misc" to false. This means that, by default, comics won't have the "M" marking.
  
$misc=false
  
// This will create a sudo-array, with exploded values.
  
list ($stripNumber,  $extension) = explode ('.'$filename);
    
//let's check to see if the comics are marked "M" 
    
if (substr($stripNumber, -1) == 'M'){ 
      
//if it does, we'll set is as a misc comic, and it wil be singled out and picked on by normal comics.
      
$misc=true;
      
// Now were still needing to retreive the number of the strip without that M. This will remove the M.
      
$stripNumber substr($stripNumber0, -1); 
    }  
// End IF
  // This will add a new element to the array of comics. Each element will have 3 sub-elements.
  
$comic[] = array('misc'=>$misc'stripNumber'=>$stripNumber'extension'=>$extension);  
}
?>
<table border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#333333" bgcolor="#CCCCCC">
  <tr> 
    <td width="130" bgcolor="#FFFFFF"> <div align="center"><font face="Arial, Helvetica, sans-serif">Comic Category </font></div></td>
    <td width="130" bgcolor="#FFFFFF"> <div align="center"><font face="Arial, Helvetica, sans-serif">Strip ID </font></div></td>
    <td width="130" bgcolor="#FFFFFF"> <div align="center"><font face="Arial, Helvetica, sans-serif">Image map </font></div></td>
    <td width="130" bgcolor="#FFFFFF"> <div align="center"><font face="Arial, Helvetica, sans-serif">Image</font></div></td>
  </tr>
  
<?php 
  $stringTag 
"<td width=\"130\" bgcolor=\"#FFFFFF\"> <div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\">";
  for (
$loops=count($comic); $loops 1$loops --) {
  echo (
'<tr>');
  echo (
$stringTag "&nbsp;");
    if (
$comic[$loops]['misc']) {
      echo (
"Filler Comic");
    } else {
      echo (
"Storyline Comic");
    }
  echo (
$stringTag $comic[$loops]['stripNumber'] . "&nbsp;</td>");
  echo (
$stringTag "." $comic[$loops]['extension'] . "&nbsp;</td>");
  echo (
$stringTag " image unavailable </td>");
  echo (
'</tr>');
  }
?>
</table>
The output
NOTE: "Image Unavailable" isnt an error. I just havent added that particular portion yet.

Last edited by Raraken; 05-22-2004 at 12:53 AM..
Raraken is offline   Reply With Quote
Old 05-22-2004, 01:58 AM   PM User | #2
Raraken
Regular Coder

 
Join Date: Jan 2004
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Raraken is an unknown quantity at this point
Never mind. Instead of figuring out a way to have it add the first two, I'm just going to have it remove them, and sort em again. :P
Raraken is offline   Reply With Quote
Old 05-22-2004, 01:58 AM   PM User | #3
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
i think the problem is here
PHP Code:
if ($handle opendir('comics/')) { 
   while (
false !== ($file readdir($handle))) {  
       
$strip[] = $file
   } 
   
closedir($handle);  

because i would suspect that . (current dir) and .. (parent dir) are also returned.
so it should be
PHP Code:
if ($handle opendir('comics/')) {
   while (
false !== ($file readdir($handle))) { 
       if ((
$file != '.') and ($file != '..')) { 
           
$strip[] = $file
       } 
   }
   
closedir($handle); 

as you or the coder would have seen if they read on to example 2 in the manual (i knew i'd seen that code somewhere before)
http://www.php.net/manual/en/function.readdir.php
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html
raf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:10 AM.


Advertisement
Log in to turn off these ads.