lurah Posted September 15, 2006 Share Posted September 15, 2006 I try to readdir(links_db/) and fgets(links_db/filename) first line of file.Idea is to create selection box, where $file is value and first line of file is what is output on selection box.[code]<?php function list_catagories() { $folder = opendir("links_db/"); // from this directory we want files listed $file = readdir($folder); while ($file) { if ($file != "." && $file != "..") { // if it's not dir it's .txt (no else files on that directory) $handlefile = @fopen($file, "r"); // we open it $cat_name = fgets($handlefile, 4096); // first line is name of category $cat_name = str_replace(array("\r", "\n"), "", $cat_name); // EOL marks out of there echo "<option value=\"".$file."\">".$cat_name."</option>"; // and let's spit it on <option></option> fclose($file); // this file is done } $file = readdir($folder); } closedir($folder);}?><form action="links.php" method="post"><p><select name="category"><option value="">Links Main menu</option> <?php list_catagories(); ?></select><input type="submit" value="Ok"></p></form>[/code]First listed file wont open and it's $cat_name dont show up on select box. Only empty line.When i choose one of those values from <form> nothing happens.Here is links.php what uses code above.[code]<html> <head> <title>ASCII-World - Related Links</title> </head> <?php include"../css/style.html"; ?> <body bgcolor="#606060"> <center> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td align="left" bgcolor="#606060" width="100%" colspan="2" class="header"><font face="Arial" size="2" color="#FFFFFF"><b>INTRODUCTION:</b><br><br></font> </td> </tr> <tr> <td width="50%" colspan="2" bgcolor="#606060" > <p align="justify"> <font face="Arial" size="2" color="#FFFFBB"> <b>text blaablaa</b> </p> </td> </tr> </tbody> </table> </center> <table align="center" cellpadding="0" cellspacing="0" border="0" width="80%"> <tr> <td align="left" bgcolor="#606060" width="50%" colspan="2" class="header"> <?php include"select_catagories.php"; ?> </td> </tr> </table> <HR><?php// selected category $cat_file = $_POST['category'];$handle = @fopen("links_db/".$cat_file, "r"); // let's open selected link list file if ($handle) // file handling/reading { while (!feof($handle)) // file reading loop start { $address = fgets($handle, 4096); // first line is URL $site = fgets($handle, 4096); // secons line is name of site $desc = fgets($handle, 4096); // third is description if ($address != "") // if there is anything to output { echo "<li><b>"; // font, size and colors. <li> too echo "<a href=\"".$address."\" target=\"Blank\" >".$site."</a></b><br>"; // we spit our link out on screen echo "<font face=\"Arial\" size=\"2\" color=\"#FFFFBB\">".$desc."</li><br><br></font>"; // let's not forget description } // end of (if $address) checking } // file reading loop endfclose($handle); // close file}?> [/code]All help is welcomed. Im pretty lost with this one now. Quote Link to comment Share on other sites More sharing options...
lurah Posted September 15, 2006 Author Share Posted September 15, 2006 Well, some solution. Not beautifull but it works ;D[code]function list_catagories() {$folder = opendir("links_db/"); // täältä luetaan tiedostot $file = readdir($folder); while ($file) { if ($file != "." && $file != "..") { // jos ei ole hak. niin sitten se on .txt kun muita filuja siellä ei ole. $temp = file("links_db/".$file); $cat_name = $temp[0]; $cat_name = str_replace(array("\r", "\n"), "", $cat_name); // draizin kiva rivinvaihto poistaja echo "<option value=\"".$file."\">".$cat_name."</option>"; // tungetaan tiedoston nimi ja ensimmäinen rivi valinta laatikkoon } $file = readdir($folder); }closedir($folder);[/code] 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.