Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Reading Directories, Populating Select Box


Can anybody tell me how to read through a directory, get the file names and populate a select box(pulldown menu) with these names? I know how to loop through a directory using something like this:

while ($files = readdir($handle)) {

$ext=substr($file,-4);

if ($files != "." && $files != ".." && $ext == ".php") {

do some wild and crazy stuff here;

}

}

It's the populating the select box (pulldown menu) while doing this that I need the help on.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Populating A Select Box
What I want to do for members of my website is to allow them to click a button that will add their name to a list that populates a select box.  I can do this on my own, but I was curious if I have to use a database in order for this to be possible. 

Populating A Select Box From A Database
I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it.

The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like:

Green
Red
Blue
Green
Black

How can I make it so that Green only shows up once?

Populating SELECT Multiple Form Field And Inserting Into Db
I have an update form where I'm trying to populate a SELECT multiple field with a list of 48 categories, from tbl work_cat. And show, as SELECTED, the one or many choices that the user had previously selected from the 48 categories which are stored in tbl cat_relations as $relation_cat.

Then allow the user to update their selections and update the database. But I can't get my form to work. First problem, I can't get the SELECT field on the form to show the categories, and then I don't know where to go from there. Below are my form page and my processing page. Code:

Populating A Second "select" Field
is there a way to populate a second select field in a form based on input for a first select without reloading and using only php? Code:

Creating Directories In Directories
I'm building a document management system and I've hit a snag. I'm relatively new, so this might be obvious to someone else.

A user can add folders into the system (kinda like Windows Explorer) and then add folders IN those folders. I have a database set up to track the child/parent relationships but I'm having trouble with the actual creation of the directory on the server.

I pass the "add folder" script the NAME of the new folder as well as the PATH of the new folder. If I'm in the root directory and I add a "TEST" folder I pass "TEST" as the folder name and "" as the path, because we're adding at the root.

If I've added "TEST" and I want to add "IN TEST" inside the "TEST" folder I send "IN TEST" as the new folder name and "TEST" as the path. My code then adds a "/" and calls mkdir. So the path passed to mkdir is "IN TEST/TEST". Code:

Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution.

So it goes <select name='status[]'>... <select name='resolution[]'>

Then i have a another php page.
$status = $_POST['status'];
$resolution = $_POST['resolution'];

Now my question is, how do i do the sql query statement?

mysql_query("SELECT * from bugs where status=$status and resolution=$resolution");

The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.

SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

PHP + MYSQL, Populating Drop Down Box
I am looking to generate a dropdown box from MYSQL data:

db name = h2, table = Working, Column = Home.

Populating Two Combo Boxes
I have one combo box (Category) which is populated by a MySQL table using php. I am trying to use the onchange javascript to submit the value selected so that I can populate the other combo box (sub-category) based on what was previously choosen. So can anybody give me a clue on how to submit the first boxes value so that the second can see what was selected (javascript function).

Populating Dropdown List
I am wanting to know how to populate the <SELECT> dropdown menu with all existing values from the DB and also have the value associated with that id selected. This is an updating area of my admin. Any ideas? Here's the code so far. At the moment it only retrieves the value assigned to that id. PHP Code:

Populating A Drop Down Menu
How would I go about populating a Drop Down menu from data in MySQL? If you can show me wither a URL to learn this, or if you feel like telling me here, that would be great.

Dymanic Populating Checkboxes
i like to retrieve a value from DB,
accordingly i like to display the checkbox, either checked or not.

Now im able to retrieve the value from DB, i can show even show the
checkbox, but i cant make it checked????

the Code i used to display as follows,

#Require the database class
require_once('../dbinfoinc.php');

#Get an array containing the resulting
record
$query = "SELECT * FROM event";
$result = mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
if(($i % 2) == 0) { $c =
'"TableDetail"' }
else { $c = '"TableDetail2"' }

$event_id=mysql_result($result,$i,"event_id");

$event_name=mysql_result($result,$i,"event_name");

$event_publish=mysql_result($result,$i,"publish");
// if(($event_publish) == 0) {
$event_publish = 'No' }
// else { $event_publish = 'YES'
}
$take_action = 'Delete'
echo "<tr>
<td Class='navText'
align='center' class=$c>$event_id</td>
<td class='navText'
class=$c>$event_name</td>
<td class='navText'
align='center' class=$c><input type='checkbox'
name='publish' if($event_publish==1){'CHECKED'}?></td>
<td class='navText'
align='center' class=$c><a
href='delete_event.php?event_id=$event_id'>$take_action</a></td></tr>";

$i++;
}
?>

Re-populating A Form If Errors
I am learning php. I have created a simple Web page with a form.
After receing the POST request, I do some error checking. In case of
errors, I would like to re-post the page, but with the current values
for each field.

I have organized my files like this:
1) Webpage with the form (all in html, form action points to a php
file)
2) php file that receives the request.

Populating Form Text Box.
I have a PHP form for entering data on-line into a mySQL
table..
Because of the intended search facility, I require one field in the form
to be completed with exact and precise item names and spelling.
In testing, I had achieved this with look-up tables.
Ideally I would like the selected item from one of five drop-down lists
to autopopulate the form text field when selected.
Alternatively at least the option of copy and paste.
Copy and paste - for some reason will not work.
Autofill worked fine on a test form with no database connection
and in standard HTML and javascript, however, once the PHP
is added to the page neither method works.
Could anyone please point me in the direction of how to get the
autofill to work?

Populating Drop Down And Table
I have a database with the following fields.
Name | Company | Date

values in each column could be repeated, or not. as in there could be several same names with the same company with different dates, or different names with same company.

How do I populate a table with this info and have drop down boxes, so that I can narrow down the search? For example:
Name | Company | Date
12     | 1           | 1929
13     | 1           | 1929
14     | 1           | 1929
12     | 2           | 1929
12     | 4           | 1929
13     | 1           | 1941
12     | 6           | 1929

So if in the drop down I select '12' under name, only those entries with 12 are shown, and then I can further sort it by selecting only '1' under Company.
Hope I'm clear, I manage to complicate things when I post them.

Populating An Auto_increament Attribute
I have just designed a BD. there are companies with auto increament which are integer. When I try to populate it after i tool value from another form and try to insert it into a table i recieve an error! I don't ask the companyID value from user as it is auto increament. Don't tell me to put NULL for that entry as it didn't work as well! Code:

Populating Table Information
I am trying to dynamically generate bgcolors with to help populate some information for a site. Here is the code:

Auto Populating A Drop Down Box
Basically I'm setting up a website which needs an populated drop down box made up from all fields in a specific column of a table in a mysql db....

Here's the code I've made up using various tutorials....

<?php 
$user = "";  
$host = "" 
$password = "" 
$dbName =  "" 

/* make connection to database */  
mysql_connect($host, $user, $password) OR DIE( "Unable to connect 
to database"); 
mysql_select_db($dbName); //did you forget this line? 

$sql = "SELECT model FROM usedVehicles"; 
$query = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT 
?>

<form action="action" method="post"> 
<select name="option"> 

<?php  
while ($row = mysql_fetch_array($result)) {  
    echo "<option value="" . $row['model'] . "">" . $row['model'] . "</option>
";  
}  
?> 
</select> 
<input type="submit"> 
</form>

I've left out the connection details for obvious reasons... When I upload and try to test this, jus a blank drop down appears... there are definately fields in the column as I have tried the query on phpMyAdmin.

Populating Fresh Data
Im building a live web chat using php, mysql, javascript, ajax I am fine with sending and retreiving data in real time using ajax as the transfer protocol However, my problem, which is becoming a nightmare, is how to I display it !! Lets say the below is the chat screen,

<div id="messages">
Jamie - Hello
Peter = Hi
Jamie = Nice Day
Peter = I know
</div>

Lets say Jamie's next message is "What are you doing today". I can send that off to the database no problem and I can get peters live chat to pull that message in, however, how do I get it to display underneath Peter = I know

As a practice I was using

document.getelementbyid('messages').innerHTML = document.getelementbyid('messages').innerHTML + "<BR>What are you doing today"

That works, but, lets just say the chat gets to 1000 lines, for each new message those 1000 lines have to be pulled out via javascript, a new line written to it and then printed back in the div

Im not sure but I'd take a good guess at this not being optimal and will cause CPU load on the users machine

What is the best way to do this! Chat messages are deleted after 1 minute, but that doesnt matter because by then they have already been sent the the users chat. Just incase you are thinking of completely repopulating there chat with every message they have sent since the chat started..

Populating Form Item From SQL Enum Set Rev#2
$sql = "SHOW COLUMNS FROM table LIKE 'subject' ";
$qry = mysql_query($sql) or die("Query not valid: " . mysql_error());
$res = mysql_fetch_object($qry);
// This returns a row with a field 'Type' containing 'enum(...)'

$res->Type = str_replace('enum('', '', $res->Type);
$res->Type = str_replace('')', '', $res->Type);
//now the string is something like this: one','two','three

$temp = explode('','',$res->Type);
//temp is an array with as much elements as the enum

while ($temp)
print array_pop($temp);


This way is much more easier using the elements since they are elements
of an array. Cleaver isn't it?

Populating Array With Mysql Results
I'm returning a result set of one field in a table, and want to populate an array with the results. I can't for the life of me figure out a simple way to do this without using mysql_fetch_array() to cycle through the results, append that to a var, then explode that into a var and pass that. PHP Code:

Populating A Form Wth Database Info
I've coded a piece of code which populates a form with data read from the database:

$connection=mysql_connec ("localhost", "f2821842", "f2821842");
$result=mysql_select_db("QUERIES");
$query=mysql_query("Select * from Emp_Details where emp_num = '$employnum'");
while($row=mysql_fetch_array($query))
{$empname=$row['emp_name'];}

<form name="webregform" action="webadmin2.php" method="post">
<input name="requiredname" type="text" size="30" value="<?php echo "$empname"; ?>">
</form>

When I echo the $requiredname, I get spaces and no data, and I know that $empname is not a space-it does read a value in a database. 1. How can I get $requiredname to print a value?

Populating Dynamically Generated TextFields
If one assigns something to the value iattribute off an input /text field, that value will be displayed when the form is loaded. My problem is, when building a form dynamically, the only way I can get the text to show is by doing the above, however, as this is an update form, when the form POSTS to processUpdate.php,
both the data entered by the user AND the data in the value attribute are inserted/updated.

So, how does one dynamically build a form where the data is displayed in the text fields but value atttribute is not set. PHP Code:

Populating A Drop Down List With The Year
i'm trying to loop the years from 1960 - 2010 with the function get_year() below:
PHP Code:

Populating Form Fields With Variables
The script itself works fine: mail gets sent. If there are any missing fields the form displays again with a list of the missing fields, but I can't get the form fields of the reloaded form to be populated with teh existing values. PHP Code:

Populating DHTML Menu From MySQL
I have a client that would like to have drop down menus added to a nav
bar that is generated from MySQL. Is it possible to have a dynamically
driven DHTML menu from MySQL?

Populating Arrays From MySQL Query
I have the following code: http://pastebin.com/746601

The field 'material' in 'is_material' contains multiple values for each
record in 'is_details'. Because of this I have used
'is_material_lookup' as a reference lookup table containing the
'style_code' and 'material_code' which refer to their full details in
the respective tables.

Currently I have got the script outputting all the details and one
material then in the next block of data, repeating the details with a
different material. What I would like to achieve is having 1 block of
data with a list of all materials in that, instead of the repeat, but
sadly I can't know exactly how to do it.

Populating Dropdown With Mysql Entries
I would like to create a combobox in Flash which is populated with mysql data and programmed with php. For example: There are 3 entries in database .ie. apple, bannana, peach. Now these I want in combobox in Flash MX/flash5.

Populating A Drop Box With Results From Database
I have a MySQL database with a table (category) with two fields, catId (int) and category (char(50)). What I want to do is to get all category names in this database and place all of them into a dropdown box on a web page so that the user can choose from the list of available categories.

Populating Table With Text File
My web hosting service uses phpMyAdmin and at the bottom of the screen
iis an area where I can upload a text file to populate a table.

I have a table named groups with two fields:
groups_idauto-increment primary
groups_name

So how do I create my text file to populate this table?

I'm going to use MS Notepad.

If it's set to auto-increment, do I need to include the number? If
so, does it start at 0 (zero)?

Would the file look like:

0,students
1,faculty
2, staff

or just

students
faculty
staff



PHP Not Populating Form Variables Passed Through POST Or GET
I"m running:

Windows Xp SP2
Apache2
PHP5
MySQL4

Everything seems fine and dandy, and I can do scripting on server side, but for some reason I cannot get data from a form to be put into a variable.

I have a simple form in an html page which submits, and in the php script that handles the input, none of the data in the form is going into the variables.

My php.ini file does have all the GPC's in place(ie variable_order, the way they get processed).

Auto Populating Multiple Drop Downs.
im trying to create two dropdowns, i need the first one to be the category and the second one to be the subcategory.  The category drop down autopopulates with the correct info from the database. and uses the table "category", the value of each drop down is represented by the "cat" field in the table (cat is basically and integer id number) and "Category" is used as what the user actually sees in the drop down (category is the actual word of the category).

Once the category is selected i would like to have the sub category auto populate with everything that has the same values as the selected category (cat)

Here is a break down of how the tables work.

Table 1 Name: "category"
Fields for Table 1:  "cat" (the id number), "category" ( the actual name of the category)

Table 2 Name: "subcategory"
Fields for Table 2: "cat" (corresponds with the cat id from table 1 to pull the correct data), "subc" (the basic id of the subcategory), "subcat" the actual name of the subcategory.

so the way i see it, have a normal drop down populated by a php query. then on change, populate subcategory drop down where cat = cat and display sub category.

Populating The Drop Down And Pressing The Submit Button
1. The first is I have two drop down menus. The first is "year" and the second is "mfr". When a user selects a year from the drop down it then populates the second drop down, mfr, from the MySQL database. Theat is working fine. But the problem I am having is the "submit" button (which I have labeled as "browse"). When I click it. Nothing happens, no action tacks place. I have looked over the code and I can't figure it out. (See Code Box 1 Below).

2. Right now the "mfr" drop down is populated by the MySQL database and reads with a list like "Acr", "Alp", etc. These are abreviations. I need to set up an array to have them instead read the entire mfr name. Example: Instead of "Acr" it needs to be "Acura". Instead of "Alp" it needs to be "Alpine". I need these full names to appear in the drop down. I know I need to do something like this (See Code Box 2 Below) but I can't get my finger on it. Code:

Sub Directories
What i would like to know is how with php can i create a subdirecty and copy some files into there?

Populating City,state,country Drop Down Menu
In the registration form I have city, state, country fields. I was
wondering if there was a database available on the net which has the
list of states in each of the countries. That way when a user selects
a country I could automatically populate the state drop down menu ...

Populating Form From Database, Then Passing Results To Next Page
I have a multiple select input in a form that's being populated by a row
from my database as such:
<input type="checkbox" name="subm[]" value="$row[ID]">

That part is working fine as I can check the displayed page using View
Source and see that the value is the correct row number from the
database. It is then being submitted on a form by $_POST method to
another page where I want to evaluate the checkboxes and display the
contents of the entire row that corresponds to each value="$row[ID]"
that have been checked. But I can't seem to get it to work. I'm having a
problem passing the selected value. Can someone point me in the right
direction?

$query = ("SELECT * FROM `table`");
$result = mysql_query($query);

print "<p>Data for Selections:";
print "<table border=2><tr><th>You chose:";

foreach ($_POST['subm'] as $value) {
print "<tr><td>";
print "$row[ID];
";
print mysql_field_name($result, 1) . ": " . $row[name]."<br>";
print mysql_field_name($result, 2) . ": " . $row[address]."<br>";
print mysql_field_name($result, 3) . ": " . $row[city]."<br>";
print "</td></tr>";
print "</table>
";
}

if (!isset($_POST['subm'])){
print "<p>No matching entry ";
}

mysql_close();

Auto-populating Multiple Boxes... Php And Pg_fetch_array Problem?
There is a nice tool using jquery/php to populate multiple select boxes out
there, it must be a very stupid question but I?m trying to apply this tool to get data from postgreSQL, but I always get an empty [] value. It means that the...

Dynamically Populating Listboxes Based On Previous Selection
How do I populate the second listbox in this form based on the selection of the first listbox?

The first listbox is populated by this query:
$year_query = "SELECT distinct year FROM bench_data";
The second listbox should essentially be populated by this:
$industry_query = "SELECT distinct comp_desc FROM comp_desc, benc_data where $_POST['year']=bench_data.year and bench_data.comp_key=comp_desc.comp_key";

I know this is alot to ask, but please EXPLAIN the code.  I am new and need the explanation elucidated and not just supplied code that will accomplish the goal. Code:

Uploading Directories ?
Is there any way I can simply allow a user to upload an entire directory through php without selecting the files one by one ?

Creating Directories With PHP
Can you create directories and text files with php?

Create Directories On The Fly...
Just curious to know is it possible to create directories on the fly?

What I have done is created a script when you can add categories and subcategories, but what I would like to do is create a directory physcially within that category. For instance using the mkdir command using linux. In a way traversing through and creating a directory.

An example would be:

If I created a category called business and econony then it would display this in the address bar.

http://www.domain.com/Business_and_Economy

Then perhaps under Business and Economy, a category called Accounting, then it would display the following:

http://www.domain.com/Business_and_Economy/Accounting/

Hopefully I'm making some sense here.

Heres the code:

function maketree($rootcatid,$level)
{
$sql="select catid,cat_name
from quiz_category
where parentid=$rootcatid
order by cat_name";

$result=mysql_query($sql);

while (list($DBcatid,$DBcatname)=mysql_fetch_row($result))
{
$width=($level+1)*24;
$display="<img src=http://www.domain.com/spacer.gif border=0 width=$width height=12>";
if ($DBcatid==1)
{
$display.="<input type="radio" name="quest_type" value=$DBcatid checked>";
}
else
{
$display.="<input type="radio" name="quest_type" value=$DBcatid>";
}
$display.="$DBcatname<br>
";
echo $display;
maketree($DBcatid,$level+1);
}
}

if ($submit=='Add New Category')
{
if ($new_cat!='')
{
mysql_query("insert into quiz_category
(parentid,cat_name) values ($quest_type,'$new_cat')");

# need to create directory here

echo "<br><br><center><b>New category entered</b></center>";
}
else
echo "<br><br><center><b>New category name must be entered</b></center>";
}

Fopen() With Directories
I am attempting to create directories using a form, a user submits the directory name and the directroy is created. I am attempting to use fopen to create it, but it doesn't seem to be working. Is there a way to use fopen()? Also, could opendir() be used instead?

Code: <form action="create.php" method="post">
Site Address: <br>
<input name="subdir" width="30" type="text"> <input type="submit" value="create">
</form> PHP Code:

Virtual Directories?
Virtual Directories?

I've been working with ColdFusion for my real job and sticking with PHP
for my side work and have a question. In CF, they have virtual
directories you can set up that you can use the address of
mydomain.com/admin and have it access files from another location on the
same server thisdomain.com/clientadmin

I was wondering if there is something similar to this in PHP. I run a
reseller account on a server and can access databases from different
domains, so I was hoping this could be possible. If anyone has any
ideas, please let me know.

Traverse Directories
My problem is that I can't find a way of referencing files and
includes statically. I have to change each page reference so that when
it is referenced it references the correct document. As I want a
central location to keep all my most used 'includes'.

So if I change a scripts location I also have to change the script
it's self to point to the correct documents. This is a problem when
the directory structures hierarchy keeps changing.

Also HTTP referencing is out as the scripts will not all be run on the
same servers.

Converting ?PID=whatever To Directories?
I've got a product directory with a product detail page for all products. The way the product page is displayed in the address bar is productdetail.php?PID=# Would it be feasible for a newbie like me to do so that instead of putting in the question mark it's in directories similar to Amazon?

Different Timezones In Different Directories
I have a strange problem. Iset up php 5.1.6 on my Solaris10 box and
after that i get errors on my webbpage:
"Warning: date() [function.date]: It is not safe to rely on the
system's timezone settings. Please use the date.timezone setting, the
TZ environment variable or the date_default_timezone_set() function. In
case you used any of those methods and you are still getting this
warning, you most likely misspelled the timezone identifier. We had to
select 'UTC' because your platform doesn't provide functionality for
the guessing algorithm"
I searched a little and foun out by setting up date.timezone in php.ini
it works.
Bur then I have to recompile php for support of zlib, and after that, I
get the error again. Now I found out the following:
# pwd
/usr/local
# php -i |grep timezone
Default timezone =Europe/Luxembourg
date.timezone =Europe/Luxembourg =Europe/Luxembourg
#
# cd ..
# pwd
/usr
# php -i |grep timezone
Default timezone =UTC
date.timezone =no value =no value
How is it possible that, when I'm in /usr/local the settings are OK,
and in all other location the settings are not.
Here header output of phpinfo:
PHP Version 5.1.6

System SunOS my-web 5.10 Generic_118844-19 i86pc
Build Date Nov 5 2006 16:24:04
Configure Command './configure' '--prefix=/usr/local'
'--with-mysql=/usr/local/mysql
'--with-apxs2=/usr/local/apache2/bin/apxs' '--with-zlib=/usr/local'

Copy In 2 Directories
I've got a simple question.
Is it possible with the command "copy" upload a file via browser on two
different directories?

I use copy

copy("$file", "/directory1/$superdat_name")

Sync Directories
I have a php script on a cron job running every half an hour that FTPs to a given server and downloads files, heres a list of everything it does:

     1. Checks file names in the FTP directory with a database table
     2. Downloads any new files and imports the file information into that table
     3. Uploads all the information inside that file into a different database table
     4. Deletes file on the local machine that was downloaded, as to not take up space

Now, the FTP directory keeps a full 60 days worth of files which is about 8640 files,  everything so far works perfectly, efficiently and doesn't need to be changed. 

However I want to add a function, in everything it does I want it to check if any of the files in the database have been deleted on the FTP server.  As to have only the 60 days worth of file records in the table.

File Directories
I searched the forums and didn't see an answer to this question.

I need to store a lot of files on my server, ~100 000 files. The files range from 800kb to 30MB. Would it make a difference in search time for PHP to find a single or multiple files if all the files were in one directory, or should I map them over several directories (e.g alphabetically)?


Copyright © 2005-08 www.BigResource.com, All rights reserved