473,385 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using a .txt document within a select tag

I have an assignment that I need to use a select tag to list three cities. I know how to code in html for a select tag.
This is what I have already working


Expand|Select|Wrap|Line Numbers
  1. <select name="city" size="1">
  2.         <option value="0">-</option>
  3.         <option value="Chicago">Chicago</option>
  4.         <option value="Detroit">Detroit</option>
  5.         <option value="Toronto">Toronto</option>
  6.     </select>


Now what I need is the same results ^^ that gives you but by using a seperate .txt file for the cities. This is the code I have written. I know that the read file code is working fine. What I can't figure out is how to input the information in the select tag. I am sure, I am having a simple syntax issue but I really need to get this figured out.


Expand|Select|Wrap|Line Numbers
  1. $filename = 'data/'.'cities.txt';
  2.  
  3.         $lines_in_file = count(file($filename));
  4.  
  5.         $fp = fopen($filename, 'r');   
  6.  
  7.         for ($ii = 1; $ii <= $lines_in_file; $ii++)
  8.         {
  9.             $line = fgets($fp);  
  10.             $city = trim($line);
  11.  
  12.             print"<select  size='1'>;
  13.                 '$_POST['$city']';     
  14.                 </select>";
  15.         }
  16.  
  17.         fclose($fp);

Thanks for the help!
Mar 1 '13 #1
2 1379
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

On line 13, why are you printing out the city from the post array? Just use $city. The $_POST array is to retrieve data that was passed to the page from a form.
Mar 1 '13 #2
divideby0
131 128KB
It's been a couple of years since I did anything php or html for that matter, but if your data file had each city on its own line in the file, then you might try something like below.

Expand|Select|Wrap|Line Numbers
  1. $out = "<select name='city' size='1'><br />"
  2.      . "<option value='0'>--</option><br />";
  3.  
  4. while(($buf = fgets($fp)) !== FALSE)
  5. {
  6.    $out .= "<option value='" 
  7.         . trim($buf)
  8.         . "'>"
  9.         . trim($buf)
  10.         . "</option><br />";
  11. }  
  12.  
  13. if(!feof($fp))
  14. {
  15.    fclose($fp);
  16.    exit("FILE READ ERROR: " . __LINE__);
  17. }
  18.  
  19. $out .= "</select>";
  20. echo $out;
  21.  
  22. ....
  23.  
Mar 2 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Razzbar | last post by:
I need to be able to conditionally load a remote script, using the "<script src=..." syntax. Or some other way. I've seen people writing about using the document.write method, but it's not working...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
3
by: Toboja | last post by:
Hello, I have two select lists: Available Sort Options and Selected Sort Options. The user clicks on any of the available sort options and can move them to the selected sort options box. I use...
7
by: David Hayes | last post by:
I tried finding an answer on http://www.quirksmode.org/ without success. I am attempting a complicated Frames structure. I have made it work in IE, but not Netscape. I begin with three...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
1
by: Tor Inge Rislaa | last post by:
Using PowerPoint within my application I am developing an application that needs some functionality of displaying some text and graphic in full screen modus, as when you run a PowerPoint show....
3
by: scripter199 | last post by:
Hi, Im adding textboxes dynamically from an onclick event that calls the function below: function addRowDynamic() { rowCnt++; lookupCnt++; id++; //add a row to the rows...
2
by: lintolawrance | last post by:
how we can get the record count of a datalist using document.getElementByID()
3
by: duyanning | last post by:
I have written a pyhton script that will process data file in current working directory. My script is in an different directory to data file. When I debug this script using pdb within emacs, emacs...
2
by: carmelo | last post by:
Hello, I'm working on a DB on which I can run only SELECT commands, so I'd like to modify this UPDATE command, which makes use of CASE: update Table set field2 = case when (SUBSTR(field,1,2)...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.