My table row index starts at 2. Should start at 1.
Also the .php file should not be included in the list.
My table row index starts at 2. Should start at 1.
Also the .php file should not be included in the list.
[php]
<?php // open directory $myDirectory = opendir("."); // get entries while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } // close directory closedir($myDirectory); // count elements in array $indexCount = count($dirArray); $indexReal = $indexCount-2; // show number of songs print("\n");
Print ("Songs in table: $indexReal. \n"); print(" |
# | title | type | size |
---|---|---|---|
$index | "); print(""); $content = file($dirArray[$index]); echo ("$content[0]"); print(" | "); print(""); print(filetype($dirArray[$index])); print(" | "); print(""); print(filesize($dirArray[$index])); print(" | "); print("
[/php]
\n");
Print ("Songs in table: $indexReal. \n"); print(" |
# | title | type | size |
---|---|---|---|
$ind | "); print(""); $content = file($dirArray[$index]); echo ("$content[0]"); print(" | "); print(""); print(filetype($dirArray[$index])); print(" | "); print(""); print(filesize($dirArray[$index])); print(" | "); print("
Hello friend,
The problem is that into folder has directories “.” and “…”
To fix this problem, is very simple.
array_shift(); << this function will remove the first indice of array…
but do you have 2 indices, so… utilize two turn.
I hope that it can help you…
foreach($dirArray as $index => $value){
$ind = $index + 1; // This is to fix the correct list of indices…
if (substr("$dirArray[$index]", 0, 1) != “.”){ // don’t list hidden files
print("
Thanks so much Thiago! That worked like a charm. And I even to some degree understood a bit of it!
I tried to shorten it to:
[php]
// remove first indice of array
array_shift($dirArray);
// loop through the array of files and print them all
foreach($dirArray as $index => $value){
$ind = $index; // fix the correct list of indices
[/php]
That works too. Any reason not to do this? It seems like you did minus 2, then plus 1.
My iq is on the lower side I’m affraid. I’ll read up on the shift and foreach stuff.
Lyrics page now integrated into site. I’m so happy. Thanks everyone for everything.
Anyone know how to hide that index.php file still hangin’ 'round in the table?
Ohh, i’m sorry I forgot… To remove .php, try…
foreach($dirArray as $index => $value){
$ind = $index + 1;
// If this index has ".php", so let's to next, and doesn't print.
[b]if(strrpos($dirArray[$index], ".php") !== false){
continue;
}[/b]
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<tr><td>$ind</td>");
print("<td>");
$content = file($dirArray[$index]);
echo ("<a href=\"$dirArray[$index]\">$content[0]</a>");
print("</td>");
print("<td>");
print(filetype($dirArray[$index]));
print("</td>");
print("<td>");
print(filesize($dirArray[$index]));
print("</td>");
print("</tr>\n");
}
}
Seems it’s still included in the array? So it’s number (6) is missing in the table.
ohh yeah, it’s wrong… but, no problem ;D!!
$ind = 1;
// loop through the array of files and print them all
foreach($dirArray as $index => $value){
[b]if(strrpos($dirArray[$index], ".php") !== false){
continue;
}[/b]
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
print("<tr><td>[b]$ind[/b]</td>");
print("<td>");
$content = file($dirArray[$index]);
echo ("<a href=\"$dirArray[$index]\">$content[0]</a>");
print("</td>");
print("<td>");
print(filetype($dirArray[$index]));
print("</td>");
print("<td>");
print(filesize($dirArray[$index]));
print("</td>");
print("</tr>\n");
[b]$ind++;[/b]
}
}
I didn’t understand that. Nothing changed. Still jumps from 5 to 7.
sure? post here the code…
[php]
<?php // open directory $myDirectory = opendir("."); // get entries while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } // close directory closedir($myDirectory); // count elements in array $indexCount = count($dirArray); $indexReal = $indexCount-2; // show number of songs print("\n");
Print ("Songs in table: $indexReal. \n"); print(" |
# | title | type | size |
---|---|---|---|
$ind | "); print(""); $content = file($dirArray[$index]); echo ("$content[0]"); print(" | "); print(""); print(filetype($dirArray[$index])); print(" | "); print(""); print(filesize($dirArray[$index])); print(" | "); print("
[/php]
Alternate solution could be to keep the index.php file outside the lyrics folder and name it lyrics.php. That would require quite some code change I assume.
foreach($dirArray as $index => $value){
$ind = $index + 1; // fix the correct list of indices
// If this index has “.php”, so let’s to next, and doesn’t print.
if(strrpos($dirArray[$index], “.php”) !== false){
continue;
}
Ah! Works!
I substract none .txt files “manually” here:
[php]
// count elements in array
$indexCount = count($dirArray);
$indexReal = $indexCount-3;
[/php]
But that’s ok.
Superb!
good luck friend.
Thanks a lot. We got me started. Have so much stuff I want to add to the site. Will keep building. PHP it is.