gsencan Posted August 11, 2011 Share Posted August 11, 2011 I have a .txt like this italian,www.mydomain.com/image/italian.gif,www.mydomain.com/nation/italian.php,201108060922 /=>this is date english,www.mydomain.com/image/english.gif,www.mydomain.com/nation/english.php,201108070923 arabic,www.mydomain.com/image/arabic.gif,www.mydomain.com/nation/arabic.php,201108080924 . . . . goes on i want to show most recent 20 images by date (which exist in each line ) /And in another page i want to show most recent 21 to 40 And image name on images(italian or english etc.) with image place which i put like www.mydomain.com/image/italian.gif so when u click an image you will go to the webpage which it links to I found many codes but none of them are capable of this... any suggestions?? (not an easy way i know) Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 11, 2011 Share Posted August 11, 2011 where is the code you're working on and what errors are you getting ? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 11, 2011 Share Posted August 11, 2011 well, here's a handout... not the only way to do it, not even the best, but probably the easiest for you to understand. I left the easy part for you to solve (adding the actual images and creating the link) <?php // read file $file = file_get_contents('YOUR_FILE_NAME_HERE.txt'); // break file into lines $lines = explode("\n",$file); // create empty array to hold values $myArray = array(); // loop through each line foreach($lines as $line){ // separate fields $fields = explode(",",$line); // remove date from array and use as key $date = array_pop($fields); $myArray[$date] = $fields; } // sort array by keys (date) ksort($myArray); // initialize counter $count = 0; // loop through result and display foreach($myArray as $date => $values){ // limit to 20 if($count >= 20) break; // show data echo "<br>LANGUAGE: ".$values[0]; echo "<br>IMAGE: ".$values[1]; echo "<br>LINK: ".$values[2]; echo "<br>DATE: ".$date; echo "<hr>"; // increment counter $count++; } ?> 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.