...

View Full Version : Formatting A ( While )???



the-dream
03-12-2007, 06:14 PM
I have some PHP:



<?php
$dir = "/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo $file;
echo "<br />";
}
closedir($dh);
}
}
?>


It checks all the files in a directory then list each file on a new line.
Is there eny way of formatting each line for example the first line bg is grey the second is white the third is then grey and so on. How is this done???

raamdev
03-12-2007, 07:23 PM
<?php
$dir = "/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
$i = 0;
while (($file = readdir($dh)) !== false) {
if ($i == 0) {
$color = "#999999";
$i = 1;
}
else {
$color = "#CCCCCC";
$i = 0;
}
echo '<div style="background-color:' . $color . '">' . $file . '</div>';
// echo "<br />";
}
closedir($dh);
}
}
?>

the-dream
03-12-2007, 07:48 PM
Thats Great!
T H A N K S!

the-dream
03-12-2007, 08:06 PM
i have my code:


<?php
$dir = "/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
$i = 0;
while (($file = readdir($dh)) !== false) {
if ($i == 0) {
$color = "#999999";
$i = 1;
}
else {
$color = "#CCCCCC";
$i = 0;
}
echo '<div class="boxes"><div class="boxes" style="background-color:' . $color . '">' . $file . '</div></div>';
}
closedir($dh);
}
}
?>


and then i want a check box for each one so you could delete the file.
How???

Ty!

StupidRalph
03-12-2007, 08:17 PM
You'll have to have wrap your code with a form and dynamically write out a checkbox with each file:



echo '<div class="boxes"><div class="boxes" style="background-color:' . $color . '"><input name="del_file" type="checkbox" value="' .$file .'" />' . $file . '</div></div>';


This will make an array with the check box values...once you submit the form search to see which files have been checked and use the unlink() to delete them.

the-dream
03-12-2007, 08:30 PM
I Don't Understand!

Sorry ive been doing PHP for bout a year and a half but dident really learn anything!

StupidRalph
03-12-2007, 08:44 PM
I've replied in your other thread here...

http://www.codingforums.com/showthread.php?p=544478&posted=1#post544478



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum