JacobRyan Posted March 1, 2011 Share Posted March 1, 2011 <?php $path = "../assets/tattoos/"; $path2 = "../assets/tattoos-thumbs/"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { unlink($path. "/" . $file) or die("Failed to delete file"); unlink($path2. "/" . $file) or die("<meta http-equiv=\"refresh\" content=\"0; url=index.php\" />"); } } ?> <form name="form1" method="post"> <?php $imageDir = "../assets/tattoos/"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; echo "<input type='CHECKBOX' name='file[]' value='$file'>"; echo "<img src='../assets/tattoos/$file' style='height:auto;width:8%;' alt='$file'>"; } closedir($dir_handle); ?> <input type="submit" name="Delete" value="Delete"> </form> I have this code, which calls an image directory and adds a checkbox next to it, you check the boxes you wish, hit delete and the pictures are removed from the server. I need them to display in a grid view, like 4 columns by X amount of rows. Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
.josh Posted March 1, 2011 Share Posted March 1, 2011 example: echo "<table>"; echo "<tr>"; for ($y = 0; $y < 50; $y++) { echo ($x % 4 == 0) ? "</tr><tr>" : ""; echo "<td>" . $y . "</td>"; $x++; } echo "</tr>"; echo "</table>"; Quote Link to comment Share on other sites More sharing options...
JacobRyan Posted March 1, 2011 Author Share Posted March 1, 2011 example: echo "<table>"; echo "<tr>"; for ($y = 0; $y < 50; $y++) { echo ($x % 4 == 0) ? "</tr><tr>" : ""; echo "<td>" . $y . "</td>"; $x++; } echo "</tr>"; echo "</table>"; Sorry for my lack of knowledge (I'm still fairly new to PHP and kind of stumbling my way through it for now), where would I place that in my existing code? Quote Link to comment Share on other sites More sharing options...
.josh Posted March 1, 2011 Share Posted March 1, 2011 you don't place that directly in your code. You learn from the principle and apply it to your code. The principle is this: use a variable to act as a counter, that increments every iteration of the loop. Also within your loop, use the modulus operator to check if the current value of your counter variable is divisible by 4 (the number of columns you want). If it is, end the current table row and start a new one. Quote Link to comment Share on other sites More sharing options...
JacobRyan Posted March 1, 2011 Author Share Posted March 1, 2011 Welp I won't even pretend to know where to start with your provided example. Quote Link to comment Share on other sites More sharing options...
.josh Posted March 1, 2011 Share Posted March 1, 2011 Welp, I'm here to help people learn, not hand out freebies, as I do this sort of thing for a living. I'll be more than happy to apply the concept to your posted code and hand you the resulting code if you want to pay me for it. Or perhaps a more altruistic soul will do it for you for free. I do suggest you try to learn it though, otherwise what is the point in coding it yourself? Quote Link to comment Share on other sites More sharing options...
JacobRyan Posted March 1, 2011 Author Share Posted March 1, 2011 Welp, I'm here to help people learn, not hand out freebies, as I do this sort of thing for a living. I'll be more than happy to apply the concept to your posted code and hand you the resulting code if you want to pay me for it. Or perhaps a more altruistic soul will do it for you for free. I do suggest you try to learn it though, otherwise what is the point in coding it yourself? Question, what would be the purpose of echoing the table tag if it will be just one table? Quote Link to comment Share on other sites More sharing options...
.josh Posted March 1, 2011 Share Posted March 1, 2011 Not sure I understand the question. The example code only outputs one table. It starts out by echoing out the opening table tag and opening table row tag. Then in the loop it outputs a closing and then opening table row tag based on the condition, meanwhile outputting individual table cell tags for each value. Then after the loop, it finishes off by outputting a final closing table row tag and finally the closing tag for the table. Quote Link to comment Share on other sites More sharing options...
JacobRyan Posted March 1, 2011 Author Share Posted March 1, 2011 Not sure I understand the question. The example code only outputs one table. It starts out by echoing out the opening table tag and opening table row tag. Then in the loop it outputs a closing and then opening table row tag based on the condition, meanwhile outputting individual table cell tags for each value. Then after the loop, it finishes off by outputting a final closing table row tag and finally the closing tag for the table. Ahhh okay. The other examples I've seen a lot of people just began the <table> tag outside of the php tag. That makes much more sense now. Quote Link to comment Share on other sites More sharing options...
JacobRyan Posted March 2, 2011 Author Share Posted March 2, 2011 So I must be doing something wrong, it's repeating each image 50 times then starting a new table. Any idea's? Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 2, 2011 Share Posted March 2, 2011 show us your current code Quote Link to comment Share on other sites More sharing options...
JacobRyan Posted March 2, 2011 Author Share Posted March 2, 2011 <?php $path = "../assets/tattoos/"; $path2 = "../assets/tattoos-thumbs/"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { unlink($path. "/" . $file) or die("Failed to delete file"); unlink($path2. "/" . $file) or die("<meta http-equiv=\"refresh\" content=\"0; url=index.php\" />"); } } ?> <form name="form1" method="post"> <?php $imageDir = "../assets/tattoos/"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_handle))) { if($file == "index.php") continue; if($file == ".") continue; if($file == "..") continue; echo "table"; echo "<tr>"; for ($y = 0; $y < 4; $y++) { echo ($x % 4 == 0) ? "</tr><tr>" : ""; echo "<td><input type='CHECKBOX' name='file[]' value='$file'><img src='../assets/tattoos/$file' style='height:auto;width:50%;' alt='$file'></td>"; $x++; } } echo "</tr>"; echo "</table>"; closedir($dir_handle); ?> That's what I have it to now. It's repeating the directory in a vertical row, then making a new one next to it. Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 2, 2011 Share Posted March 2, 2011 Cursory glance - you are ending your table rows OUTSIDE the 'while loop' move them to be the last part of your while loop Quote Link to comment Share on other sites More sharing options...
JacobRyan Posted March 2, 2011 Author Share Posted March 2, 2011 Doesn't seem to matter where I move the echo for ending the table row I seem to terminate it to earlier then I'm left with a long list of the same picture repeating based on whatever value y has. And if I leave it outside the loop then, I get a table of the same image, but I guess at least it's a table? Quote Link to comment Share on other sites More sharing options...
.josh Posted March 2, 2011 Share Posted March 2, 2011 remove the "for ($y...)" loop. In the example code, that loop was meant to simulate the "while" loop you already have for looping through the files. Quote Link to comment Share on other sites More sharing options...
.josh Posted March 2, 2011 Share Posted March 2, 2011 and you also need to put these lines before the "while" loop. echo "table"; echo "<tr>"; (and you also need to have "<table>" not "table") Quote Link to comment Share on other sites More sharing options...
JacobRyan Posted March 2, 2011 Author Share Posted March 2, 2011 Success, thank you! Finally get what I was doing wrong. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.