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




Convert CSVs To Select Option Values


I was just wondering if someone could point me to a good web resource that could help me figure out how to convert a string of comma separated values (being pulled from a database) into a select menu (pulldown box) so that the values from the CSV would automatically fill in the displayed text area of the option tags as well as the value attribute so the value selected could actually be passed as a variable.

I imagine it has something to do with converting the CSV list into an array using substring parsing & then dynamically building the array from the elements of the array, but I just haven't been able to put it all together yet. If anyone is familiar with anything published on the web that might help, I'd be deeply appreciative.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Select <option> </option>
I have this script in a form, it is trying to send a selection from the from to the next page. But the proble is that if the selection has a space in it, it only sends the first work to the next page. Code:

Option Values
From my experimentation there seems to be a difference when using values from an option value as apposed to an value by a check box etc. I can quite easily input data from a check box selection, but not an option value. Code:

Select Option
How do i click on an option and  then automatically sort a mysql query by that value? I can get a set of option to appear and can do a query but not combine them? Code:

<select> Option
I know PHP is a server-side language, so it's not client-sided. What I want to do is have a <select> dropdown with options and I want the page to refresh itself and display some information on that option. The problem is that since PHP isn't client-sided, I don't know how to get the value of the selected option and display the relevant info on that option. Any ideas on how to do this with PHP?

Default Option On Select Box
I need to make a field in a admin form to be a drop down select box. I have the field right now as: PHP Code:

Remaining Value For Select Option
i've used $_SERVER[PHP_SELF] , so my form and script are just one file .
when a user click the submit and have some errors the sript reload again ,
for a reloaded script i've put :(for exaple)

<input type="text" name="username" value=$_POST[username] />

so when it reload the last information the uer has typed won't be delete.it stays.

i want to do the same with my "select menu " , i don't know how , the select menu reset when script reload :(example)

gender :
<select>
<option value="">select one</option>
<option value="m">male</option>
<option value="f">female</option>
</select>

Select/option Action?
I am trying to figure out how to click an option in a select menu and have that option act as a hyperlink/form submit without a submit button. Here is an example of what I am trying to do: Code:

Selecting Option In Select?
I am trying to populate a drop down list from values in an array, and compare a $_REQUEST or $_SESSION value to each of the array values. If they are equal, then the option in the drop down menu will be selected. Can't get it to work... Here is my code:

White Space In Select Option
I'm having a problem with a <select><option> which has white space in
values...

When I post the data I only get the first word (up to the white space).
"Testing white space" becomes "Testing" after posting

<select name="descr" id="descr">
<option value=Testing white space>Testing white space</option>
<option value=Testing white space two>Testing white space two</option>
<option value=Testing white space th>Testing white space th</option>
</select>

I am using form method = post and have also tried method = get

How do I get the full string from the value field.

Getting Right Order Of <option>s In <select> After Submit
I'm trying to emulate part of our client-server application as a web
site so customers can use it, and I'm stuck when it comes to
re-ordering items in a list.

Basically we have a list of available articles ("availableItems") and
a list of articles already in an issue ("selectedItems"). What I want
is to be able to move articles freely between the two lists and then
on submission add them to the issue (which I can), but also move items
in the "selectedItems" list around so that they can be re-ordered
(i.e. I want the customers to be able to change the order in which the
articles appear in the issue).

I can do both these things on screen (i.e. I have written Javascript
to move them from one box to the other (add/delete them from
"selectedItems") and to move individual articles up or down the list
of articles in the issue. Befor submitting I run a Javascript loop on
the list to select them all, from top to bottom. On screen it always
selects them in the right order (i.e. top to bottom, no matter whether
I have changed the order of these items) but when I grab the array
containing the item id numbers it's as if the change in order had
never happened!!!

Newly added or deleted papers get added/deleted fine, but when I fetch
the array from "selectedItems" I always end up with the items in the
same order, with the latest items added at the end. However, being
able to change the order of these items is crucial for this project,
but so far I have been unable to do this and I haven't found any
information on how to grab the new ORDER of items.

Here's some of the code:

I retrieve the array like this:

/*
$ia_items_new = $_POST['selectedItems'];
*/

However, this still lists the items in the OLD order:

/* if ($ia_items_old) {
foreach($ia_items_old as $key => $value) {
//echo("<BR>Old: No.".$key." - ".$value);
}
}
/*

Populating the "selectedItems" box:

/*
print( " <td><select multiple size=&#3920;'
" );
print( " id='selectedItems'
" );
print( " name='selectedItems[]'>
" );
//Grab values if the information was found
$in_total_count = $objRSIssueBatord->RecordCount();
$counter = 0;
if ($in_total_count > 0) {
//Now put in an entry for every value in the batting order list:
//Get the recordset ready and extract data:
$objRSIssueBatord->MoveFirst();
while (!($objRSIssueBatord->EOF)) {
$counter ++;
//Get the variables and make string to describe items
$in_paper_id = $objRSIssueBatord->fields("bip_paper_tracker_id");
$is_jsp = $objRSIssueBatord->fields("jsp_code");
$is_customer_no = $objRSIssueBatord->fields("pap_customer_no");
if (!$is_customer_no) $is_customer_no = "N/A";
$is_author = $objRSIssueBatord->fields("pap_author");

Simple - UD Function With Select / Option
As you might guess I am completely new to this language. Maybe I get some
help here.
I try to execute a user defined funciton from a select option in a document
to read a file
into an array without using a submit button or anything else.
like this:
<select name="sel[]" onchange="<?php ReadFile(DependingOnValue);<?" >
<option value="1"> 1st Quarter </option>
<option value="2"> 2nd Quarter </option>
<option value="3"> 3rd Quarter </option>
</select>

I know I could use Javascript instead. But I am sure there is an easy way
doing in PHP.

Keeping Select Option Value Selected
I'm trying to learn how to keep the value "selected" once a form is set to read the values and then f-write them (all within a loop). The part that's giving me a problem is the part which would return the value of the form as "selected". PHP Code:

Multiple Select Box With Selected Option ...
first of all I have three tables (tournament_game, umpire_game, umpires). Updating tournament_game umpires, each game may have from two to four umpires, and those umpires can work from one to n number of games, that's why I'm using connection table umpire_game. I'd like to get selected multiple select box of umpires in game, it could be two to four options, with all umpires listed as options example:

<select name=umpire_game[] size=10 multiple>
<option value=$umpire_id>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>
<option value=$umpire_id selected>$umpire_name</option>

PHP Code:

Select Option Stays Selected
I have a normal drop down menu:

<select name="status" class="db_list_text">
                    <option value="All" selected="selected">All</option>
                    <option value="True">Active</option>
                    <option value="False">Inactive</option>
                  </select>
The idea for this is for the user to select either true or false and then to click submit to find data that matches either one. The coding is in the same page so the form basically just reloads the page and grabbes whatever info is requested. How can I with PHP, make it that the dropdown stays on the selected option when the page is reloaded?

If/Else Statment Within An Select/Option Group
I want to create an update query in a form so that I can update my groups attendance. The variables 100% are working and are pulling the correct info.  In the update attendance column, I would like an If else statement that says if the attend_status == present echo  SELECTED VALUE="", so that the pull down menu will display the current attendance value. From there I will select the new update attendance info and then submit it using an update query.

Below is the code. I am running into other problems with the quotation marks in such because this is all located within the <php> tags. Code:

CSVs
In PHP, my hoster doesn't allow MySQL so instead I've decided to use CSV files. They will be used to display Images. I know these can work like this as my friend uses it in that way. What I want is to have each record in the CSV file and display each record like so:

Name,PIC,Description, in a PHP document. I was wondering how I can do this. eg: <img src = "<?php echo $img ?>"> That would be to display the image. I have no problem with connecting to the file, it's just displaying each record as each record on a page not, just the words and commas.

Getting All Select Box Values
I'm running into a problem with a select box. Its values in PHP are not properly parsed.

<select name="frm_owners" size="10">
    <option value="1">Apples</option>
    <option value="2">Oranges</option>
</select>

Now, if I were to select both options and then output $_POST[frm_owners] on another page, all I would get is "2." But I'm looking for a comma-seperated value like "1,2." Any ideas?

Select Distinct Values In Only 2 Columns
I have a table where a customer may have multiple accounts.

I want to eliminate duplicate values for Customer_ID and Account_ID -- regardless of their state or region.

I tried this,

SELECT (DISTINCT Acct_ID, Cust_ID), Address, City,State, Zip,Country, Contact, State_ID,Region_ID,
FROM t_table

but it doesn't work.

This (below) does work, but it gives 2 records. One record when a person is listed once in a target state, and a second record if that person is listed in an overlapping region.

SELECT DISTINCT Acct_ID, Cust_ID, Address, City,State, Zip,Country, Contact, State_ID,Region_ID,
FROM t_table

(this is the same as)
SELECT DISTINCTROW Acct_ID, Cust_ID, Address, City,State, Zip,Country, Contact, State_ID,Region_ID,
FROM t_table

Is there any other way to select distinct values in only 2 columns?

Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table

so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.

Popup Window List Of Values To Select
What i need to do is bring up a popup window with a list of values(values looked up from the database). The user should be able to select one of the values from the list and the value then populate a text box on the calling form.

Run A Select Statement Based On Array Values?
I have an array that has x number of values. I want to run a sql statement x number of times using the next array value each time. Basically I have a query that displays results based on a search. The result of the search is a list of names, the trouble is for reasons beyond my control the names are in a single db field as "FirstLast".

I want to take this value and match it up to another table that has the first and last names in separate fields. So far I have extracted the results from the first query using a while loop, the resulting array is called $name_search: Code:

Comparing User Input Values In A Form With Database Values
I want to compare user input values in a form with my database.
Basically I want to check whether the user exits in my database.
What mysql command can do that?

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:

Option Value
I have a drop down menu and I want to insert the selection from the drop down menu into the database. How would I go about this?

Add Option Modifiers
I am working on trying to create an admin for a product catalog, the only problem i am having involves product modifiers such as the ability to add size and color to the product that can also increase the cost of the product.

I was wondering if anyone would know a really good way of going around to do this, the only way I can think of is having a product option table that would hold the value of the modifier plus the cost plus the product id that this references too plus its own special id.

PHP GTK Option Questions
Before I invest more time in researching and testing I am curious if anyone knows for certain if a PHP_GTK application running on a Windows machine can communicate and interface with a remote database SECURELY?

My plan involves creating a support system which would be a standalone application on a Windows Workstation. This application would query data from a remote database SECURLY and then support personal would be able to modify, edit, etc. data from the PHP_GTK application which would in turn update data in the remote database, again securely.

Can a PHP_GTK application support this, security being the biggest concern?

Readdir & Option Value
more or less that is my problem:

i'm making HTML <select><option> statement:

if ($dir = @opendir("/the/directory)) {
while($file = readdir($dir)) {

echo '<option value="'.$file.'">'.$file;
}
}

the number of options depends of number of files in directory.

When user chooses one of this files(he chooses an option) i want to know
what option he choosen.

Option Button ?
I want to create a form with 3 groups of 2 options buttons (radio buttons in Dreamweaver). Can someone helps me in sending links to PHP Reference ? Example:

a > 0
Option(Yes) Option(No)

b > 0
Option(Yes) Option(No)

c > 0
Option(Yes) Option(No)

Submit Button Action of the submit button: If option_a_yes is checked (...) then open html.

Remember Me Option
Any ideas on how to create a remember me option in a login box..?

Pagination Option
Below (A) is a portion of my pagination code where I specify the limit. What I'd like to do is add a select function (B) that will allow users to specify the limit. On change of select option, it should refresh with the new limit: Code:

Option Selection
I am making a Option Box (Drop down bar) for Gender, (Male,Female) and I want when they Select there Gener, and then hit submit, it Writes to to a Database.

i have it set it up so far that it goes to another page to INSERT it into the Databse.

Option Value Remember
When a user clicks on a car the option box selects what car has been choosed, after filling the form in and if he has forgotten to type some info, the script echos what did he forget, and the prob is, that the option value disappears.
How can i save the value or post it over? Code:

Imap_mail_move Or Imap_mail_copy Option
To develoment.

I use imap function by UW imap4 at PHP.

imap_mail_move function can have option CP_UID for coping UID by PHP manual.

but UID does not copy.

I don't know why it is not.

I hope to detect the reason.

PHP 4.3.x
UW IMAP4

Editable Option List
I fill a list of option from a mysql table

$resultprod = mysql_query ("describe my_table");
while($row = mysql_fetcharray($resultprod)) {
echo ('<option value="' . $row['Field'] . '">' . $row['Field'] .
'</option>');
}
echo "</select>";
}

but I would also like the user to be able to add it´s own value if the
value he/she want to enter is not in the mysql table. how can I do
that?

Multiple Option Button
I have 2 fields username and password inside a form + 3 options (member, affiliate and admin) each one has different file (member.php, affiliate.php and admin.php) thus each option have a different post file. how can you do it in php to have 1 form with the mentioned but forwarding to the selected option file.

PHP And A Pre-selected Option In A Form
I've got a little text editor thing on my site, and to open a file, you input the file name and choose the folder from a drop-down list and click the Open button. The default filename is "index" and that file keeps track of all the files contained in that folder. It works okay. What's annoying is that regardless of what folder you're messing around in, the drop down list always goes back to showing the default folder name as the page is reloaded. I want it to be preselected to the folder it's in.

It seems simple enough--the folder you're in is $_GET['dir']. But I've read some HTML form how-tos, and I can only see that you can preselect using the tabindex="" or selected attribute.

Setting Selected Option Using PHP
I have a drop down list which I want to be set to what was selected when the form is submitted. As the form is processed by the same page, it returns to the preset default. How would I go about making this selection box set the option selected on the next page?

Adding New Values To An Array That Already Contains Values..
is it possible to append new values to an array that already has values in it??

say, i have my existing array;

existing array;
$array = array([66314] => 66314 , [66315] => 66315) ;

then , when i check my checkbox on my next page, the ids should be appended to the $array:

array that needs to be added to the $array;

$array = array([66316] => 66316,[66317] => 66317,[66318] => 66318);

how should it be done??

Code For Downloading Option Used In Websites
Most of the web sites offer a downloading options ( As we see in most of the
CMS ). On selecting a file, it asks where to download the file. I have tried
several ways, but none of them are working. Please help me, as i want to keep
this option in my site design.

Search Query + Checkbox Option
I am a newbie poster to the site and have just started using php and mysql - have been painstakingly getting dummy site set up which sells CDs, I have searched this site to find the answer to my prob; which is:

On the catalogue page - user or guest can search the catalogue using text field, but I also want the option of choosing from 4 checkboxes (they can all be checked) for type of music e.g. C&W, pop, rap, blues. Also, they can input year of release and price (but I haven't got around to how to do that yet! - maybe another text field or )....

Get The Info Depending On The Selected Option
I have a page that is intendend to update a table field on DB i have a drop down menu wich displays all the position fields available on db and a text area where i will insert the new data.

now the problem: I'm using the query SELECT * FROM table WHERE position = $position
the $position is the choosen option from the drop down menu. then have echo "<textarea>$functions</textarea>" where it will show to me the present data available on DB after all this, i have another query UPDATE table SET functions = $functions WHERE position = $position

All is ok and working except the fact that he doesn't displays $functions
when selecting a option from the drop down menu?

Selecting <option> With Preg_replace Vs Loop - Which Is Better?
and does testing merely mean running it 100 000 times and clocking it?

// using preg_replace :

$s = '
<select name="color">
<option value="">choose
<option value="red">red
<option value="green">green
<option value="blue">blue
<option value="yellow">yellow
</select>'

if($_POST)
{ $c=$_POST['color'];
$s=preg_replace('/(value="'.$c.'")/','$1 selected',$s);
}

echo $s;

// using loop :

$colors=array('red','green','blue','yellow');

echo '<select name="color">'
echo '<option value="">choose'
foreach($colors as $c){
echo '<option value="'.$c.'"'
if($_POST['color']==$c)
echo ' selected'
echo '>'.$c;
}

echo '</select>'

Set The Selected Text For Option Box Of A Menu..
Having major issues with this simple task, and I cant work out why its
not doing as it should/expected.

Basically, ive got a drop down box with the added bit of php:

<select name="title" id="title">
<?php
if($_SESSION['title'] != "") {
echo '<option value="'. $_SESSION['title'] .'"
selected="selected"></option>'
}
else {
echo "<option value="" selected></option>";
}
?>

<option>Mr</option>
<option>Mrs</option>
<option>Miss</option>
<option>Ms</option>
<option>Dr</option>
</select>

Basically, if the user submits a form, the title is stored in the
session, this works fine, and then when returned to the page, the value
should be filled in.

Yet, when they return to the page, there value they selected is not
shown in this box, instead, theres just a gap. The source seems
correct, and this is whats shown:

<select name="title" id="title">
<option value="Mr" selected="selected"></option>

Option Explicit? (On Dimming Variables...)
Is there such a thing as ASP's Option Explicit in PHP, where I require
variable declarations? This prevents typos and I find it useful at
least for me.

Detecting Checkboxes And Option Lists
I am trying to figure out how to detect a <Form> check box being checked in a PHP script.  Likewise, I am trying to figure out how to detect which option was chosen in a <option> list of drop-down items in a form. Code:

How To Get Form To Remember Selected Option?
I am now trying to make a form remember which color (a select list) they selected before pressing any of the submit buttons. I entered this code into the form:

<select name="color">
<option value="red">red</option>
<option value="blue">blue</option>
</select>

The submit is a GET type. For example, if the user selects blue and then clicks on either one of the "submit" buttons, I want the form to remember/show the blue option. Right now the select list always goes back to red, the first choice. I tried doing a <?php echo $red; ?> and <?php echo $blue; ?> for the option value, but this does not work since the select list needs a value.

Dynamic Form Option List
I want to create a dynamic drop down option list in a form, but I just can't wrap my head around this.

Both of the below scripts work as intended, but how do I make the mySql query results work with my existing script?  Yes, I know I must replace the "$options = array" part in the top piece of code, but I need a little more guidance than that. Code:

Best Way To Show Selected Option In List Box
I need a way so that we can show selected option in list box without using if condition in loop since some times we have lot of options and we have too much if conditions to check.


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