PHP - Dropdown List With Db Tables And Files
Hello everyone
I have two dropdown lists. First one you can see the tables of my db and the second one the files inside a folder. The problem is that i can't send my selections from the dropdown list to an other file. My project is to choose a table, then a CSV file and then load the file in db. index.php: Code: [Select] <?php //EMFANISH PINAKWN include("../forma/dbCon.php"); echo "<form action='load_table_test.php' method='POST'>"; $sql="SHOW TABLES FROM misthodosia"; $result=mysql_query($sql); if (!$result) { echo "Υπάρχει πρόβλημα με την βάση\n"; echo 'MySQL Error: ' . mysql_error(); exit; } echo"<select>"; while ($row = mysql_fetch_row($result)) { echo "<option name='{row[0]}' value='{row[0]}'>{$row[0]}</option>"; } echo"</select>"; mysql_free_result($result); //==========================EMFANISH ARXEIWN========================== function populateDropdown(){ $path = glob("C:\\xampp\\htdocs\\dbadmin\\upload_files\\*"); //the double \\ is not a typo you //have to escape it //if the path cannot be found if(!($path)){ echo("Δεν υπάρχει ο φάκελος"); return; }//if //the path is valid else{ foreach($path as $k){ $i = basename($k); echo "<option name='$i'>".$i."</option>"; }//foreach }//else }//populateDropdown echo"<select>"; populateDropdown(); echo"</select> "; echo"<input type='submit' name='submit' value='Φόρτωσε1111111' />"; echo "</form>"; $hello="hello"; ?> load_table_test.php: Code: [Select] <?php include("../forma/dbCon.php"); echo $_POST['hello']; echo $_POST['{row[0]}']; echo $i; //$pinakas=$_POST['pinakas'] //$arxeio=$_POST['arxeio'] //$pinakas=$_POST['row'] //$arxeio=$_POST['diadromi'] //mysql_query("LOAD DATA LOCAL INFILE "$arxeio" INTO TABLE $pinakas //FIELDS //TERMINATED BY ',' //ENCLOSED BY '\"' //LINES TERMINATED BY '\n') echo "$arxeio"; echo "$pinakas"; echo "<br/><br/><br/><br/><br/><a href='index.php'>Επιστροφή στην προηγούμενη σελίδα.</a>"; ?> errors: Code: [Select] Notice: Undefined index: hello in C:\xampp\htdocs\dbadmin\load_table_test.php on line 6 Notice: Undefined index: {row[0]} in C:\xampp\htdocs\dbadmin\load_table_test.php on line 8 Notice: Undefined variable: i in C:\xampp\htdocs\dbadmin\load_table_test.php on line 9 Notice: Undefined variable: arxeio in C:\xampp\htdocs\dbadmin\load_table_test.php on line 27 Notice: Undefined variable: pinakas in C:\xampp\htdocs\dbadmin\load_table_test.php on line 28 Similar TutorialsHello I have a simple question about file handling... Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs, and put the content of their file into an array? Like this: array: [SomePath/test.php] = "All In this php file is being read by a new smart function!"; [SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";and so on, until no further files exists in that rootdir. All my attempts went totally crazy and none of them works... therefore i need to ask you for help. Do you have any ideas how to do this? If so, how can I be able to do it? Thanks in Advance, pros I have been working with a telephone directory that I created for a php class and it consists of three files: One file to write, one file to read and the html directory. Well, four if you include the contacts file. We have to take the file this week and create a two column table with an array from the contact file. I cannot for the life of me figure out how to get an array into two separate columns of a table with the php code. I will post the code here that I do have (the one I attempted to do the table on is scary..because as I said it's not working like I had hoped, but I did try!) Any sort of direction here would be much appreciated. I have looked through my book and online but all I can find online is examples with SQL and we aren't that far into the class yet. My book doesn't offer any sort of help with tables, just the arrays, so I am stumped and this assignment is due tonight! They have tutoring rooms but I had to take the baby to the doctor this morning and didn't make it in time and they are closed now. :-( Thanks in advance for any type of help of advice you can offer! This is my form: Code: [Select] <html xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body> <form action='phoneWrite.php' method='POST'> <!--Username: <input type='text' size='15' maxlength='25'>--> <h1>Telephone Directory</h1> <br> <table align='Left'> <tr> <td>Last Name:</td> <td><input name='LastName' /></td> </tr> <tr> <td>First Name:</td> <td><input name='FirstName' /></td> </tr> <tr> <td>Street Address:</td> <td><input name='StreetAddress' /></td> </tr> <tr> <td>City:</td> <td><input name='City' /></td> </tr> <tr> <td>State:</td> <td><input name='State' /></td> </tr> <tr> <td>Zip:</td> <td><input name='Zip' /></td> </tr> <tr> <td>Area Code:</td> <td><input name='AreaCode' /></td> </tr> <tr> <td>Phone Number:</td> <td><input name='PhoneNumber' /></td> </tr> <tr> <td></td> <td><input type="submit" value="Register" /></td> <td></td> </tr> <tr> <td></td> <td><input type="reset" value="Clear" /></td> <td></td> </tr> </table> </form> </body> </html> This is the php used to write data: <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <?php if (empty($_POST['LastName']) || empty($_POST['FirstName']) || empty($_POST['StreetAddress']) || empty($_POST['City']) || empty($_POST['State']) || empty($_POST['Zip']) || empty($_POST['AreaCode']) || empty($_POST['PhoneNumber'])) echo "<p>You must enter your information.</p>\n"; else { $lName = addslashes($_POST['LastName']); $fName = addslashes($_POST['FirstName']); $address = addslashes($_POST['StreetAddress']); $city = addslashes($_POST['City']); $state = addslashes($_POST['State']); $zip = addslashes($_POST['Zip']); $area = addslashes($_POST['AreaCode']); $number = addslashes($_POST['PhoneNumber']); $NewEntry = "$lName, $fName, $address, $city, $state, $zip, $area, $number\n"; $ContactFile = fopen("contacts.txt", "ab"); if (is_writeable("contacts.txt")) { if (fwrite($ContactFile, $NewEntry)) echo "<p> Registration Success!</p>\n"; else echo "<p> Registration Failed, please try again.</p>\n"; } else echo "<p> Cannot add registration to the database.</p>\n"; fclose($ContactFile); } ?> <form action = "phoneRead.php" method='POST'> <h1>Telephone Directory</h1> <p>Last Name: <input type="text" name ="LastName" size = "20" /></p> <p>First Name: <input type="text" name="FirstName" size = "20" /></p> <p>Street Address: <input type="text" name="StreetAddress" size = "20" /></p> <p>City: <input type="text" name="City" size = "20" /></p> <p>State: <input type="text" name="State" size = "20" /></p> <p>Zip: <input type="text" name="Zip" size = "20" /></p> <p>Area Code: <input type="text" name="AreaCode" size = "20" /></p> <p>Phone Number: <input type="text" name="PhoneNumber: size = "20" /></p> <p><input type="submit" value="Register"/></p> <p><input type="reset" value="Clear" /></p> <a href="http://localhost/MillerAssignment4/contacts.txt">Read file</a> </form> </body> </html> And this is what I have so far on the table/read file: <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <?php if ((!file_exists("contacts.txt")) || (filesize("contacts.txt") == 0)) echo "<p> There are no entries in your telephone directory.</p>\n"; else { $ContactArray = file("contacts.txt"); echo "<table style = \"background-color:lightgray\" border = \"1\" width = \"100%\">\n"; $count = count($ContactArray); for ($i = 0; $i < $count; ++$i) { $CurrMsg = explode("~", $ContactArray[$i]); echo "<tr>\n"; echo "<td width=\"5%\" style=\"font-weight:bold\">Name: </span> " . htmlentities($ConNum[0]) . "<br />\n"; echo "<span font-weight:bold\">Phone Number: </span><br />\n" htmlentites($ConNum[2]) . "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; } ?> </body> </html The contact.txt file is attached if you want to look at it Hi, I am trying to call the data from Mysql but I am getting an empty drop down list, this is the code: mysql: Code: [Select] create table years ( yearID integer auto_increment, year varchar(30), primary key (yearID) ); insert into years (yearID, year) values ('1', '2007-2008'); insert into years (yearID, year) values ('2', '2008-2009'); insert into years (yearID, year) values ('3', '2009-2010'); insert into years (yearID, year) values ('4', '2010-2011'); insert into years (yearID, year) values ('5', '2011-2012'); insert into years (yearID, year) values ('6', '2012-2013'); PHP: Code: [Select] <?php require_once('../Connections/connection.php'); ?> <?php $result = @mysql_query( "select yearID, year, from sss.years"); print "<p>Select a year:\n"; print "<select name=\"yearID\">\n"; while ($row = mysql_fetch_assoc($result)){ $yearID = $row[ 'yearID' ]; $year = $row[ 'year' ]; print "<option value=$yearID>$year\n"; } print "</select>\n"; print "</p>\n"; ?> Thank you! I am trying to find a script that will show just the file names of files in a specific directory. I tried this code posted previously on this forum and it works but shows the directory name. Code: [Select] <?php filesInDir('attachments'); function filesInDir($tdir) { $dirs = scandir($tdir); foreach($dirs as $file) { if (($file == '.')||($file == '..')) { } elseif (is_dir($tdir.'/'.$file)) { filesInDir($tdir.'/'.$file); } else { echo $tdir.'/'.$file."<br>"; } } } ?> Result is: attachments/Sedona_and_Slot_Canyon_links.docx Thanks for the help. Hi im using ftp_rawlist () to list files in my web hosting folder /public_html/ it works fine, but is there anyway to only show/list .php & html files? Hi, I'm automating a process of Inserting a CSV to a database. I'm doing it in PHP. I need to go to http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/ and get the list of the files in this directory. Which is the best way of doing it in PHP? Best Regards, If I can get this fixed, I will have completed all but the admin login for this project - my first php/mysql project. Here is what I need. I have a list_records.php that list all the records in the table 'links' and the category each entry is in from the table 'categories'. Here are my table structures. Code: [Select] -- Table structure for table `categories` -- DROP TABLE IF EXISTS `categories`; CREATE TABLE IF NOT EXISTS `categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `categories` varchar(37) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=40 ; -- -------------------------------------------------------- -- -- Table structure for table `links` -- DROP TABLE IF EXISTS `links`; CREATE TABLE IF NOT EXISTS `links` ( `id` int(4) NOT NULL AUTO_INCREMENT, `catid` int(11) DEFAULT NULL, `name` varchar(255) NOT NULL DEFAULT '', `url` varchar(255) NOT NULL DEFAULT '', `content` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`), KEY `catid` (`catid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ; On the update.php file, I have a form that lets me make changes to the record. Here is the codes for update.php Code: [Select] <? include "menu.php" ?> <? include "db.php" ?> <?php $id=$_GET['id']; $sql = "select * from links where id =$id"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)){ $id = $row['id']; $catid = $row['catid']; $name = $row['name']; $url = $row['url']; $content = $row['content']; //we will echo these into the proper fields } mysql_free_result($query); ?> <table width="65%" align="center"> <tr><td align="left"> <form action="updated.php" method="post"> <input type="hidden" value="<?php echo $id; ?>" name="id"/> <br> <b>Website Name:</B><br> Change the name of the website listing.<br> <input type="text" value="<?php echo $name; ?>" name="name"/> <br> <br> <b>URL:</b><br> Change the URL of the website listing.<br> <input type="text" value="<?php echo $url; ?>" name="url"/> <br> <br> <b>Description:</b><br> Change the description of the website listing.<br> Limit 255 characters.<br/> <textarea name="content" cols="45" rows="4" wrap="soft"><?php echo($content);?></textarea> <br> <?php $result = mysql_query("SELECT id, categories FROM categories") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $id = $rows["id"]; $categories=$row["categories"]; $options.= '<option value="'.$row['id'].'">'.$row['id'].'-'.$row['categories'].'</option>'; }; ?> <SELECT NAME=catid> <OPTION VALUE=selected><? echo $catid; ?><? echo $options; ?></OPTION> </SELECT> <?php mysql_close(); ?> <div align="center"> <input type="submit" value="submit changes"/> </div> </form> <br> </td></tr></table> The part of he code I need help with is Code: [Select] <?php $result = mysql_query("SELECT id, categories FROM categories") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $id = $rows["id"]; $categories=$row["categories"]; $options.= '<option value="'.$row['id'].'">'.$row['id'].'-'.$row['categories'].'</option>'; }; ?> <SELECT NAME=catid> <OPTION VALUE=selected><? echo $catid; ?><? echo $options; ?></OPTION> </SELECT> I want it to default to the category that the entry is in. If you look, you will see in the select portion that I I have Code: [Select] <$ echo $catid; ?> which echos the proper category ID, but if I use Code: [Select] <? echo $categories; ?> it echos Writing, which is the last category in the list. Yet, the $options echo the catid and it corresponding category. How can I get the default option to echo BOTH the catid and category name while also listing all the other categories so that the records can be moved to a new category is needed? Any help will be appreciated. Thank you in advance. Hi. I am using this script to populate a dropdown list box from sql, it works but does anyone know how to sort the list in alphabetical order? $sql="SELECT * FROM Fish WHERE ***** = '".$_GET['stocktype']."'"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $ID=$row["ID"]; $Stock=$row["Commonn"]; $Options.="<OPTION VALUE=\"$ID\">".$Stock; } <SELECT NAME='stock1'> <OPTION VALUE='$Options'>$Options</option> </SELECT> Alright, so I have an xml file differences.xml that is being parsed in XML. This is what the xml looks like: <item code="lM" name="dog"> <cost>5000</cost> <Start>12/15/2010</Start> <End>01/13/2011</End> </item> <item code="lF" name="cat"> <cost>5000</cost> <Start>04/15/2010</Start> <End>04/23/2011</End> </item>[/ I want to have the item names (dog, cat) show in a dropdown menu so that I can select these items for editing before storing in my mysql database. This is the php code I have so far: <?PHP $xml = simplexml_load_file("differences.xml"); $object = $xml->xpath("//item"); echo '<SELECT name=object>'; foreach ($object['name'] as $key => $value) { echo '<OPTION value='.$value.'> '.$value; } echo '</select>'; ?> I do have a dropdown list but there are no values inside it (it is empty). Can anyone help me figure out why? I do have this code that does work which lists the items in plaintext (not in a dropdown) so hopefull this will help us out: <?PHP $xml = simplexml_load_file("differences.xml"); $object = $xml->xpath("//item"); $count = count($object); $i = 0; while($i < $count) { echo '<h1>'.$object[$i]['name'].'</h1>'; $i++; } ?> Hey, I have the following coding: Quote <? $dbuser="*******"; $dbpass="*******"; $dbname="virtuda_db"; //the name of the database $chandle = mysql_connect("localhost", $dbuser, $dbpass) or die("Connection Failure to Database"); mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser); $mainsection="license"; $query1="select name from license"; $result = mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1); //do the query while($thisrow=mysql_fetch_row($result)) { $i=0; while ($i < mysql_num_fields($result)) { $field_name=mysql_fetch_field($result, $i); echo $thisrow[$i] . " "; //Display all the fields on one line $i++; } echo "<br>"; //put a break after each database entry } ?> How would I set up this so that instead of just "listing" them out on new lines, it would list the results into a drop down list? Thanks! This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=316599.0 I have the following code currently: Code: [Select] <?php foreach ((array)$node->field_buy_at as $item) { ?> <?php print $item['view'] ?> <?php } ?> I would like to make the list a drop down with a link so that when a user selects, he goes to a new page. I tried the following: Code: [Select] <select name="select"> <?php foreach ((array)$node->field_buy_at as $item) { ?> <?php $url = $node->field_buy_at[0]['url']; $store = $item['view']; ?> <? echo "<option value='$url'>$store</option>";?> <?php } ?> </select> I'm pretty sure it's this "$url = $node->field_buy_at[0]['url'];" that I don't have correct. Hey Guys, I know it may seem pretty simple, but im having trouble populating a drop down list. Here is my code at the moment, but what it's doing is displaying the names all in one value, where it should be in separate select values. *Note that i have only done it to the first one. See attachment. 'AntonMatt' are next to each other, they should be separate select values. Code: [Select] <? $id = $_GET['id']; $selectplayers="SELECT * FROM players WHERE club='$club' AND team='$team'"; $player=mysql_query($selectplayers); ?> <table class='lineups' width="560" cellpadding="5"> <tr> <td colspan="2">Starting Lineup</td> <td colspan="2">On the Bench</td> </tr> <tr> <td width="119"> </td> <td width="160"> </td> <td width="69"> </td> <td width="160"> </td> </tr> <tr> <td>Prop</td> <td><select name="secondary" style="width: 150px"> <option value='' selected="selected"><? while($rowplayer = mysql_fetch_array($player)) { echo $rowplayer['fname']; } ?></option> </select></td> <td>16.</td> <td><select name="secondary16" style="width: 150px"> <option value='' selected="selected">Secondary Position</option> </select></td> </tr> <tr> <td style="padding-top: 8px;">Hooker</td> <td style="padding-top: 8px;"><select name="secondary2" style="width: 150px"> <option value='' selected="selected">Secondary Position</option> </select></td> <td style="padding-top: 8px;">17.</td> <td style="padding-top: 8px;"><select name="secondary17" style="width: 150px"> <option value='' selected="selected">Secondary Position</option> </select></td> </tr> </table> </div> </div> I'm trying to sort this dropdown box. It reads from a directory, and lists the file name in the dropdown box. Here's the tricky part... the filename is listed differently in the dropdown than in the directory by using explode(). I want to sort it though since it's still being sorted by the directory listings... For example: Filename starts out as: 123_abc_567.pdf then gets listed as abc_123_567.pdf in the dropdown, but it's still getting sorted as if it were 123_abc_567.pdf How can I do that? Here's my code: // Define the full path to folder from root $path = "C:/Work_Orders/"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); echo "<form method=\"POST\" action='".$_SERVER['PHP_SELF']."' name='selectworkorder'><select name='ordernumber2'>"; // Loop through the files while ($file = readdir($dir_handle)) { //Remove file extension $ext = strrchr($file, '.'); if($ext !== false) { $file = substr($file, 0, -strlen($ext)); } if($file == "." || $file == ".." || $file == "index.php" ) continue; //explode file name $changedordernumber = explode("_",$file); //put in new order $changedordernumber = $changedordernumber[1]."_".$changedordernumber[0]."_".$changedordernumber[2]; $changedordernumber=trim($changedordernumber,"_"); //list options echo "<option name='$file' value='$file'>$changedordernumber</option>\n"; } echo "</select><input type='submit' value='Change' name='submit'/></form></div>"; // Close closedir($dir_handle); i have been trying to get this code to get a list of usernames from a database and i have now got that to work but when i try and save it it saves all the usernames from the drop down list and not just the one i have selected how can i get it to just use the one i have selected Code: [Select] <?php include "connect.php"; //connection string include("include/session.php"); print "<link rel='stylesheet' href='style.css' type='text/css'>"; print "<table class='maintables'>"; print "<tr class='headline'><td>Post a message</td></tr>"; print "<tr class='maintables'><td>"; // Write out our query. $query = "SELECT username FROM users"; // Execute it, or return the error message if there's a problem. $result = mysql_query($query) or die(mysql_error()); $dropdown = "<select name='username'>"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['username']}'>{$row['username']}</option>"; } $dropdown .= "\r\n</select>"; if(isset($_POST['submit'])) { $name=$session->username; $yourpost=$_POST['yourpost']; $subject=$_POST['subject']; $to=$dropdown; if(strlen($name)<1) { print "You did not type in a name."; //no name entered } else if(strlen($yourpost)<1) { print "You did not type in a post."; //no post entered } else if(strlen($subject)<1) { print "You did not enter a subject."; //no subject entered } else { $thedate=date("U"); //get unix timestamp $displaytime=date("F j, Y, g:i a"); //we now strip HTML injections $subject=strip_tags($subject); $name=strip_tags($name); $yourpost=strip_tags($yourpost); $to=strip_tags($to); $insertpost="INSERT INTO forumtutorial_posts(author,title,post,showtime,realtime,lastposter,name) values('$name','$subject','$yourpost','$displaytime','$thedate','$name','$to')"; mysql_query($insertpost) or die("Could not insert post"); //insert post print "Message posted, go back to <A href='forum.php'>Forum</a>."; } } else { print "<form action='newtopic.php' method='post'>"; print "Your name:<br>"; print "$session->username<br>"; print "User to send to:<br>"; print "$dropdown"; print "Subject:<br>"; print "<input type='text' name='subject' size='20'><br>"; print "Your message:<br>"; print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>"; print "<input type='submit' name='submit' value='submit'></form>"; } print "</td></tr></table>"; ?> MOD EDIT: Changed PHP manual link [m] . . . [/m] tags to [code] . . . [/code] tags. Hi i'm new to php. I want to get all the values of dropdown list on another page wether selected or not. hey all. i previously posted about how i lost all my data so im trying to recreate my form again. after not many replies from my desperate call for help i tried to figure it out on my own, i spent hours and hours going through this forum and others but im just running into brick walls because of my minor knowledge of php (though i do have to say i am picking it up a little!) my form is short and simple so this shouldnt be too hard but this is what i have come up with. my tables ---------------- Movies: ID(P_id),Title,Category (F_K),URL Categories: ID (P_Id),Category All i am needing my form to do is enter records into my movies table, therefore it goes like this: Title: "textbox" URL: "textbox" Category: "dropdown menu" "submit" now the thing here is that the dropdown menu needs to be populated with data from Category.Categories table so i can add that info into category in the movies table. so pretty much it will be sending the ID from Categories table into Category in the Movies and yes they both have the same datatype. so here is what i have so far. my form.php Code: [Select] <html> <form id="form1" name="Update" method="post" action="add.php"> <label> First Name: <input type="text" name="Title" id="textfield" /> </label> <br /> <label> Last Name: <input type="text" name="URL" id="textfield2" /> </label> <select name='Category'> <?php $con = mysql_connect("localhost", "root", ""); if (!$con) { die('Could not connect to DB: ' . mysql_error() ); } mysql_select_db ("mydb", $con); $query = "SELECT Category from Catgories"; $result = mysql_query($query) OR DIE ("There was an error .mysql_error()); while ($line = mysql_fetch_array($result,MYSQL_ASSOC)){ $categoryid = $line["playerid"]; $category = $line["category"]; echo "<option value='$categoryid'>$category</option>\n"; } php?> </select> <input name="" type="submit" value="send" /> </form> </html> and then my add.php Code: [Select] <?php $con = mysql_connect("localhost", "root", ""); if (!$con) { die('Could not connect to DB: ' . mysql_error() ); } mysql_select_db ("mydb", $con); $sql="INSERT INTO movies (title, url) VALUES ('$_POST[title]','$_POST[url]')"; if (!mysql_query($sql,$con)) { die ('Error: ' . mysql_error()); } echo "Record added"; so first things first, although i have tested the code its throwing me a variable error i think on line 30 so i figured that instead of focusing on just the error i should just have everything looked over since i dont have anyone i can turn to about this stuff to make sure i didnt forget any " or { etc.. i am also not sure if the while loop is even needed in form.php, i kind of taylored this code to my own needs. THEN i have the add.php, granted that by some miracle that the form.php is correct i dont know what else i would need to add to it for my dropdown. i really need this bad and i hope someone can help me you know. if anyone has any ideas for a more simple code please, enlighten me but just give me some good examples because i really am a beginner. thanks alot. I'm pretty new to php and I'm furiously trying to get this code to list the folders/files alphabetically but to no avail! I'd really appreciate it if someone could take a look and guide me as to what to do, I'm pulling what little hair i have left out! I can currently see the folder contents but the order is all over the place. Thanks very much!!! -------------------------- <?php $sub = ($_GET['dir']); if (strstr($sub, "..")) {$sub = "";} $path = '../media/Movies'; $path = $path . "$sub"; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if(substr($file,0,1) != ".") { if (substr($file, -4, -3) =="."){ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. $file <br />"; }else{ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. <a href='?dir=$sub/$file'>$file</a><br />"; } $i++; } } closedir($dh); ?> -------------------------- Hi Sorry if this is the wrong place for this but I'm totally stumped here and I know its a basic question but I'm very new to php and I need help :-) Basically all i would like to do is list the files and folders in the following directory alphabetically, I know i need to put them in an array etc but I don't know how and would really appreciate some help! So any help would be very gratefully received. Here's my code so far: <?php $sub = ($_GET['dir']); if (strstr($sub, "..")) {$sub = "";} $path = '../media/Documents'; $path = $path . "$sub"; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if(substr($file,0,1) != ".") { if (substr($file, -4, -3) =="."){ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. $file <br />"; }else{ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. <a href='?dir=$sub/$file'>$file</a><br />"; } $i++; } } closedir($dh); ?> Many thanks in advance! I have a script that works perfectly, for one type of file extension. What I want to do now is be able to list all files in a set of file types. I want to pass the argument to the fileSystem class's loadFiles method like this: $some_var = $fileSystem->loadFiles(DATA_DIRECTORY, "csv,xls,etc"); Then in the loadFiles method it reads the dir for each file, then test its extension. If they are of the right type, then push it on the returned array. Now I am having problems testing if the file's extension is in the array. If I use if (strpos(getExt($file), $array_of_wanted_exts))... php would match php3.. Does anybody have a better method? |