adam291086 Posted January 28, 2008 Share Posted January 28, 2008 My script currently opens up a directory and print all the pictures out with some information. What i am trying to do is print out the picture and its information into a table picture 1picture 2picture 3picture 4 picture 5picture 6picture 7picture 8 picture 9picture 10picture 11picture 12 at the moment all i am getting is a blank page. Any help is appreciated. <?php $ImageDirectory = "../pictures/thumbnail"; ?> <form action="delete.php" method="post"> <?php $BigImage = "../pictures/picture"; echo "<table border=\"1\">"; echo "<tr>"; for($i = 0; $i<= 4; $i ++) { foreach (glob("$ImageDirectory/{*.gif,*.jpg,*.png,*.GIF,*.JPG,*.PNG}", GLOB_BRACE) as $image) { //remove .. for url $dir = str_replace("..", "", "$BigImage"); //get name for url $name = str_replace("$ImageDirectory", "", "$image"); //get name on it's own $fullname = str_replace("/", "", $name); echo '<br />'; echo "<td>"; echo $fullname; echo '<br />'; echo '<br />'; echo '<img src="'.$image.'">'; echo '<br />'; echo '<br />'; echo "URL for Rich Text Editor"; echo '<br />'; echo "http://bcyorkshire.co.uk/admin".$dir.$name; echo '<br />'; echo '<br />'; echo "<a href=\"http://bcyorkshire.co.uk/admin$dir$name\">View full Image</a>"; echo '<br />'; echo '<br />'; echo '<input type="radio" name="delete[]" value="'.$image.'" />Delete '; echo '<br />'; echo '<br />'; echo '<input type="submit" value="Delete Selected">'; echo '<br />'; echo '<br />'; echo "</td>"; } if($i==4) { $i=0; echo "</tr><tr>"; } } echo "</form>"; ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/88201-solved-printing-out-into-a-table/ Share on other sites More sharing options...
adam291086 Posted January 28, 2008 Author Share Posted January 28, 2008 ok i have realised why the page was white, fixed that. Can someone help me with the logic of this. At the momenet it just looping through over and over again without stopping Quote Link to comment https://forums.phpfreaks.com/topic/88201-solved-printing-out-into-a-table/#findComment-451329 Share on other sites More sharing options...
adam291086 Posted January 28, 2008 Author Share Posted January 28, 2008 ok i have changed the code a little. It now prints out into the tabel. 5 columns across and how ever many rows down. The problem is that it repeats the same image 5 times for the row. Then move onto the next row and does the same for the next image. You can see whats happening http://cycloxchamps.co.uk/admin/pictures/view_pics.php current code <?php session_start(); // is the one accessing this page logged in or not? if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) { // not logged in, move to login page header('Location: www.bcyorkshire.co.uk/admin/login.php'); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="../../layout.css" rel="stylesheet" type="text/css" /> </head> <body class="global"><div class="layout"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="73" background="../../images/header_02.jpg"><img src="../../images/header_01.jpg" width="267" height="73" /></td> <td width="339" rowspan="2" align="right"><img src="../../images/header_04.jpg" width="339" height="226" /></td> </tr> <tr> <td height="153" valign="middle" background="../../images/header_06.jpg"><table width="669" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="../../images/spacer.gif" width="30" /></td> <td align="center" valign="middle" id="nav2"><a href="#">BC Yorkshire</a></td> <td align="center" valign="middle" id="nav2"><a href="#">National Road Championships </a></td> <td align="center" valign="middle" id="nav2"><a href="#">Yorkshire Festival </a></td> <td align="center" valign="middle" id="nav2"><a href="#">White Rose Youth League </a></td> <td align="center" valign="middle" id="nav2"><a href="#">Ryedale Rumble </a></td> <td align="center" valign="middle" id="nav2"><a href="#">White Rose Classic </a></td> </tr> </table></td> </tr> </table> </td> </tr> <tr> <td align="center" valign="top"><table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="100%" border="0" cellspacing="10" cellpadding="0"> <tr> <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <div class = "maintexttitle"> Pictures </div> <div class = "maintext"> <?php $ImageDirectory = "../pictures/thumbnail"; ?> <form action="delete.php" method="post"> <?php $BigImage = "../pictures/picture"; foreach (glob("$ImageDirectory/{*.gif,*.jpg,*.png,*.GIF,*.JPG,*.PNG}", GLOB_BRACE) as $image) { echo "<table border=\"1\">"; echo "<tr>"; for($i = 0; $i<= 4; $i ++) { //remove .. for url $dir = str_replace("..", "", "$BigImage"); //get name for url $name = str_replace("$ImageDirectory", "", "$image"); //get name on it's own $fullname = str_replace("/", "", $name); echo '<br />'; echo "<td>"; echo $fullname; echo '<br />'; echo '<br />'; echo '<img src="'.$image.'">'; echo '<br />'; echo '<br />'; echo "URL for Rich Text Editor"; echo '<br />'; echo "http://bcyorkshire.co.uk/admin".$dir.$name; echo '<br />'; echo '<br />'; echo "<a href=\"http://bcyorkshire.co.uk/admin$dir$name\">View full Image</a>"; echo '<br />'; echo '<br />'; echo '<input type="radio" name="delete[]" value="'.$image.'" />Delete '; echo '<br />'; echo '<br />'; echo '<input type="submit" value="Delete Selected">'; echo '<br />'; echo '<br />'; echo "</td>"; } if($i==4) { $i=0; echo "</tr><tr>"; } } echo "</form>"; ?> </table> </table></td> </tr> </table> </td> </tr> </table> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/88201-solved-printing-out-into-a-table/#findComment-451340 Share on other sites More sharing options...
laffin Posted January 28, 2008 Share Posted January 28, 2008 u need to get rid of this for($i = 0; $i<= 4; $i ++) { and its ending } it was looping 5 times (0, 1, 2,3,4) create a counter $ctr=0; now ya want 4 pics at the beginning of the foreach loop add if(!$ctr) echo "<TR><TD>"; $ctr++; now at end of the foreach loop (still within the loop) add if($ctr==4) {$ctr=0;ECHO "</TD></TR>";} after the foreach loop if($ctr!=0) {$ctr=3-$ctr; echo "</TD><TD SPAN=$ctr>nbsp;</TD></TR>";} u may have to tweak the last portion, but ya shud be able to figure it out from here Quote Link to comment https://forums.phpfreaks.com/topic/88201-solved-printing-out-into-a-table/#findComment-451344 Share on other sites More sharing options...
wonderm00n Posted January 28, 2008 Share Posted January 28, 2008 u need to get rid of this for($i = 0; $i<= 4; $i ++) { and its ending } it was looping 5 times (0, 1, 2,3,4) create a counter $ctr=0; now ya want 4 pics at the beginning of the foreach loop add if(!$ctr) echo "<TR><TD>"; $ctr++; now at end of the foreach loop (still within the loop) add if($ctr==4) {$ctr=0;ECHO "</TD></TR>";} after the foreach loop if($ctr!=0) {$ctr=3-$ctr; echo "</TD><TD SPAN=$ctr>nbsp;</TD></TR>";} u may have to tweak the last portion, but ya shud be able to figure it out from here Exactly what I was going to write but the forum told me that a new reply was written Quote Link to comment https://forums.phpfreaks.com/topic/88201-solved-printing-out-into-a-table/#findComment-451345 Share on other sites More sharing options...
adam291086 Posted January 28, 2008 Author Share Posted January 28, 2008 Tables and me dont get on. Works perfectly. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88201-solved-printing-out-into-a-table/#findComment-451353 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.