Raraken
05-22-2004, 12:50 AM
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
// 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($stripNumber, 0, -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 . " ");
if ($comic[$loops]['misc']) {
echo ("Filler Comic");
} else {
echo ("Storyline Comic");
}
echo ($stringTag . $comic[$loops]['stripNumber'] . " </td>");
echo ($stringTag . "." . $comic[$loops]['extension'] . " </td>");
echo ($stringTag . " image unavailable </td>");
echo ('</tr>');
}
?>
</table>
The output (http://www.shatterdesigns.com/comm/arrMaker.php)
NOTE: "Image Unavailable" isnt an error. I just havent added that particular portion yet.
How would I correct this?
My 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($stripNumber, 0, -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 . " ");
if ($comic[$loops]['misc']) {
echo ("Filler Comic");
} else {
echo ("Storyline Comic");
}
echo ($stringTag . $comic[$loops]['stripNumber'] . " </td>");
echo ($stringTag . "." . $comic[$loops]['extension'] . " </td>");
echo ($stringTag . " image unavailable </td>");
echo ('</tr>');
}
?>
</table>
The output (http://www.shatterdesigns.com/comm/arrMaker.php)
NOTE: "Image Unavailable" isnt an error. I just havent added that particular portion yet.