arbitter Posted January 1, 2010 Share Posted January 1, 2010 I would like to have 1 PHP file with 2 columns; In the first column there would be months. If you click on a month, all the picures of that month would display in the second column. And if you click on another month, only the pictures of that month display. Is it possible to do all this in one single php file? The columns also have to be 'dynamic'; Monthly 1 month adds to the lefthand column and quite a few times a photo might get added in the right-hand column, but the pictures of each month already go in seperate directories. Though this last part I can do myself; for the pictures: foreach (glob("*.jpg") as $filename) { echo "<img src='$filename' width='70%'>" ;} and for the directories i also have to use glob, but I'm not quite sure how Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 2, 2010 Share Posted January 2, 2010 Have an array of the months. Loop through it and build links back to your file with the month as a GET. You would build a simple 2X12 table with the second column spanning 12 rows. First thing your php would do is check for the GET. You would build the jan link then if you have a get spit out the pics. Then build the rest of the links. Alternatively you just use a 1X2 table and build your links in cell 1 then if you have a get spit out the pics into the second cell Actually fairly simple. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
arbitter Posted January 2, 2010 Author Share Posted January 2, 2010 Ok this might seem easy for you, but I don't quite understand it yet... I'm still a starter php'er, it's my first site, so I'm not that fluent in all these things... Could you give some more information if you have some time and if you're willing to sacrifice that time? I know how to make an array, but then looping and the get(), I don't see how the get() would get me anywhere... Quote Link to comment Share on other sites More sharing options...
knetcozd Posted January 2, 2010 Share Posted January 2, 2010 I myself am not a very experienced php'er but here goes: Maybe try storing picture links in a database , you can then refer to each 1 by their id , so regardless of where they are located in the file system you can easily access them but for this question , i would do this : page.php?month=name $month = $_GET['name'] Store you pictures in an array like so: $pictures = array( "monday"=>array("pic1","pic2"),"tuesday"=>array("pic1","pic2")); // and so on to refer to each picture you would do this : //you can easily manipulate the $pictures array without creating a new array but for simplicity i created a new array $current_month = $pictures[$month]; foreach($current_month as $key=>$value) { echo out $value; } Let me explain what i have done , " page.php?month=name " , after the "?" are get parameters , this allows you to send information via the url , to access these values simply use the " $_GET[] " super global , to get the month name submitted , simply use the param on the lefthand side of the equal-to sign as the key , like so " $_GET['month'] " , it works similar to an array. The "$pictures" array is a multi-dimensional one that will store all the months with there picture links. "foreach" is a loop that will loop through each item in the "$current_month" array. Hope this helps! Quote Link to comment Share on other sites More sharing options...
arbitter Posted January 2, 2010 Author Share Posted January 2, 2010 I have all the files stored per month so I did <?php $jan = readdir("January '10"); $feb = readdir("February '10"); $pictures = array ("Januari"=>array($jan), "Februari"=>array($feb)); ?> But that didn't quite do the trick... This is what I have in total: <?php $month = $_GET['name']; $jan = readdir("January '10"); $feb = readdir("February '10"); $pictures = array ("Januari"=>array($jan), "Februari"=>array($feb)); $current_month = $pictures[$month]; foreach($current_month as $key=>$value) { echo $value ; } ?> though nothing works 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.