Array Form A Comma Delineated List
What's the best way to create an array from a comma delineated list?
I have a string assigned to a variable that looks like this: 1,2,3,4
And I would like to create an array so that $arr[0] = 1 and $arr[1] = 2 etc.
It seems so simple but I just can't crack it.
View Complete Forum Thread with Replies
Related Forum Messages:
Comma Delineated Files
I have an file whose contents are as follows: "test","com,ma","food" $file_contents = array('"test"','"com,ma"','"food"'); Doing explode(',',$file_contents) wouldn't be sufficient because the resultant array would have four entries - not three - and would instead read like this: $file_contents = array('"test"','"com','ma"','"food"');
View Replies !
Re Comma Separated List - Another Question
I can do the match perfectly but what i also need to do is create a third list of comma separated values that are in both eg: List 1 => 1,2,3,4,5,6,7,8,11 List 2 => 1,3,4,5,6,7,10,23 Therefore List 3 => 1,3,4,5,6,7 How do I populate this third list - I'm really stuck ....
View Replies !
Comma Seperated List Comparison
is it possible to compare acomma separated list aginst another eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match? the comparison is to check that if product a who supplies products 1,2,3,4,5 can be used instead of product b who supplies 3,5 as product a already supplies them
View Replies !
How To Remove Last Comma From A Multiple List?
I have a multiple select list in my site where the values are inserted in a database table, in a column named available_country. I enter these values in the db separated with comma. I don't know however how to remove the last comma so it will be something like this: USA, Europe, Asia and not: USA, Europe, Asia, Here's what I tried but it didn't worked: ...
View Replies !
Comma Separated List In MySQL Field
say I have a list of categories in a field, and a page that is supposed to pull from the db based on a category. Is there any way I can do a query where it searches the contents of that field for the category in question? like SELECT FROM table WHERE category = $category but have it search the category field (the comma separated list for each entry) for the $category var
View Replies !
Retrieve Array From FORM List Of Values?
I have created a form where a user selects 2 items from a list of 8 values. That form field is called "choices" and returns a value to the php file as $choices. This form posed no problem when I only allowed a single item to be selected, but the client now needs to have 2 items selected at a time. The problem I'm having is that I don't know how to turn the multiple selections on the form in to an array. I thought the $choices variable would automatically become an array, but Using[color=blue] > for ( $i = 0; $i<2; $i++ ) > echo "$choices[$i] ";[/color] only returns the first two letters of the last selected item value. And [color=blue] > foreach($choices as $articles) > echo $articles. ' ' ;[/color] Returns an invalid argument. While echo $choices returns the second item selected in the list, but not the first. It appears that the variable is replacing the first item selected with the second rather than returning an array.
View Replies !
Print Array In List/menu Form Object
how i print a full column array into a list/menu form object, so that the text links to their respective page.....it is basically for a list of interviews so you click on the band name and then goto the interview page.
View Replies !
Regular Expression :: Find Word Matches To Words In A Comma-delimited List
What's the *right* way to find word matches to words in a comma-delimited list. For example, if I have the following comma-delimited list of categories in a mysql db field: gameboy, nintendo, playstation and I do a search, I know I can use regexp to do something like: select * from categories where regexp 'gameboy,' Notice that I have the comma in there to match the whole word and the comma without matching part of a word (to prevent unwanted matches such as "play" to "playstation" or "game" to "gameboy"). The problem I'm running into is words that match that match the end of each word next to the comma (in this example, "boy" and "station"). What's the right way to match a word *exactly* using regexp *without* also matching *part* of a word.
View Replies !
Seperating An Array With A Comma
I'm trying to seperate the output of an array with a comma. I can't figure out how to eliminate the last comma. Here is my code: $result = mysql_query($query,$connection) or die (mysql_error()); $fw = fopen("/var/www/html/ecast/windex/graph.html","w"); fwrite($fw, "/ "); if ($new_rows = mysql_fetch_array($result)){ do{ fwrite($fw, $new_rows[0]); fwrite($fw, ", "); }while($new_rows = mysql_fetch_array($result)); } fwrite($fw, " /"); fclose($fw); ?> Output: / 85, 86, 87, 89, / How can I eliminate that last comma?
View Replies !
Removing A Comma From The End Of An Array
I am reading a file into an array using this: $listFile = "add2db.txt"; if (!($fp = fopen($listFile, "r"))) exit("Unable to open the input file, $listFile."); $buffer = fread($fp, filesize($listFile)); fclose($fp); The very last character in that $listFile will always be a comma. What I need to do is remove that last comma (and only that comma) from $buffer before I can continue on. What do I need to do to accomplish this?
View Replies !
Exploding Comma Separated In Array
I'm looking to explode the comma separated values in an array like this: Array ( => 10811 [1] => 7527,7556 ) and then add the exploded value as a new key in the array...like this: Array ( => 10811 [1] => 7527 [2] => 7556 )
View Replies !
Create Array From Comma String
I am currently learning from the book, Eric Rosebrock's "Creating interactive websites with PHP and web services" it is a great book, but I have a question. I have a string loaded from mysql that looks like this: PHP Code: $allowedfiletypes = '".jpg", ".tif", ".gif", ".png"' I want to turn this into an array but its not working, I'm trying something like: PHP Code: $allowedfiletypes = array($allowedfiletypes); so that if I print_r it it will output something like: [0] => .jpg [1] => .gif [2] => .png etc.
View Replies !
Converting Comma Delimited Field Into Array
I have an array that goes into a MySQL database (via PHP). The only way I could find to insert them into the database was using implode. It goes into the database just great, comma separated (although I would like each to go into it's own field, but it's okay for now). The problem comes when I try to display it. Since it's comma delimited it display only the first item in the array. But there are multiple rows that should be displayed. I'm not sure how to explode it so that it will display them all. I've tried a loop but that just looped the first item in the field (the first part of the array). Code:
View Replies !
Create A Comma Delimited String That I Can Convert To An Array Using Explode();.
I am attempting to create a comma delimited string that I can convert to an array using explode();. I have the following code: Code: $cPath_new_a = tep_get_path($categories['categories_id']); $cPath_new_b = str_replace("cPath=", "", "$cPath_new_a"); $cPath_new_c = str_replace("_", "", "$cPath_new_b"); $cPath_new_d = substr("$cPath_new_c", -2, 2); $cPath_new_e = $cPath_new_d . ","; echo $cPath_new_e; This outputs 23,53, I need it to output 23,53 Using the substr($cPath_new_e, 0, -1); and/or rtrim() method to remove the last character for some reason removes all of the commas. Am I approaching this the right way?
View Replies !
List The Value From The Array
I have a textfield like: <input type="text" name="cant[]"> on the next page i have 10 textfields like this .. so i have an $cant array. how can I list the value of them from the array ? with foreach I suppose but how ?
View Replies !
Take The List From Array
Array 1= If I get an array of FRIEND_ID numbers Array 2= and an array of BULLETIN_ID numbers and somehow in this array the USER_ID of the user who created it Can I take the list from array 1 and find all matches from array2 where the FRIEND-ID in array 1 matches the userid in array 2 and have the result make a new array?
View Replies !
Array And List
trying to split up a comma seperated string into an array and then list, however having some problems, after some assistance if at all possible. I currently have a value, in $r which is 4 values seperated by commas. Im trying to put them into an error and then I try to put them in a list. I code im using. $r = '1,2,3,4' //this is my variable $urlstring = array($r); //put variable into array list($one, $two, $three, $four) = $urlstring; // problem here is that all of the values fro $r get put into the first variable in the list, $one.
View Replies !
String List To Array
I'm trying to convert a slash-delimited string to an array, but I'm wary of null elements that I want to eliminate. I'm frustrated with explode(), array_unique(), and array_pop(), and I'm wondering if there's a better way. I'm only interested in unique array elements. Here's what I've got $a = "10/20/30" should become an array where $b[0] = 10, $b[1] = 20, and $b[2] = 30. Now here's the fun part. Often my arrays will have $a = "10//" I'd like that to become $b[0] = 10 and that's all. So I tried applying array_unique() to explode("/", $a) but you have to be careful about how many elements are returned. Then I tried to use array_pop() to drop the last element if it's empty, but array_pop returns a scalar string when there's only one element left. So when you use $b = array_pop($q), sometimes there is no $b[0].
View Replies !
Setting A List Into An Array
I need some help creating a calendar display of sorts. I have a list of days as headings and under each day a list of events. Each event can have multiple bands performing. I have two tables: tbl_events & tbl_bands tbl_events contains the date, and show info and a field called band_ID which is a comma delimited list of each bands unique band_ID from table tbl_bands. Here's my problem. I want to take that list output: tbl_events.band_ID = 1,2,4,5,6 and set it into an array. If I set $band = array($rst["band_ID"]); and echo $band[0]; I get 1,2,3,4,5,6 what i need is: $band[0] = 1 $band[1] = 2 $band[2] = 3, etc....
View Replies !
Drop Down List From An Array
I want the array to contain a valid year of birth for anyone between the ages of 16 and 80. I'm pretty sure this code is correct.(though it might be a bit sloppy to all you pros) Code:
View Replies !
Array: Re-generate The Key List?
I have a script that read information from a directory (using scandir()), and puts it in an array. Now I want to filter out all files and unvalid directories (ie: '.' and '..'), so that I keep the normal/visible directories. Than I loop through the array with a while(isset($array[$i])). When I use array_filter() to filter out the unwanted files/directories from the array, it will also delete the keys. So the keys arent for instance: 0, 1, 2, 3, 4, 5 but: 2, 3, 5 When I loop through the array it will say: key 0 (in the beginning, when $i = 0) is not set and so it will stop. How can I re-generate the keys so there wont be gaps between the numbers?
View Replies !
How To Create Html List From Such Array ?
I've got an example array like this: $myArr = array( array("jj", "0", "jjj"), array("ee", "0", "eee"), array("bb", "ee", "bbb"), array("ll", "ee", "lll"), array("ff", "0", "fff"), ) Where each row is an array with columns: id of list element, id of parent list element ("0" means main node) and content of the element. So, from my array I'd like to create a list like this: <ul> <li>jjj</li> <li>eee <ul> <li>bbb</li> <li>eee</li> </ul> </li> <li>fff</li> <ul>
View Replies !
Dynamic Drop-down List In Array
Q. How do I create a dynamically-generated drop-down list for use in an array. I'm using PHP with a MySQL database (through phpMyAdmin) My database table is called com_courses, and I want to pull the distinct 'title' fields and have them appear as a drop down menu for the user to select in a form. Here is my array, with (at the moment) manually-entered 'titles' (which I now need to be dynamically generated from my database field: 'com_courses.title' array ( "coursetitle", "Course Title:", $EXTRA_SELECTLIST, array ("Report Writing", "Recruitment & Selection", "Presentation Skills", "Essential Telephone Skills", "Time Managememt", "Customer Care", "Other"), 0 ), I am not an experienced programmer, but can play around with php to customize programs. I've read up on arrays (I bought a "Programming with PHP and MySQL" book, but it just stops short of this problem). I can't figure this one out.
View Replies !
Array List Menu Problems
I am trying to store values from a List Menu into an sql database table as an ARRAY. However, when I select the multiple values from the form, it only stores the selected values as 'Array' in the SQL table. Here is the Select Statement: <select name="NOTES[]" size="9" multiple="multiple" id="NOTES"> <?php do { ?> <option value="<?php echo $row_literarydevices['LDEVICE']?>"<?php if (!(strcmp($row_literarydevices['LDEVICE'], $row_Recordset1['NOTES']))) {echo "selected="selected"";} ?>><?php echo $row_literarydevices['LDEVICE']?></option> <?php } while ($row_literarydevices = mysql_fetch_assoc($literarydevices)); $rows = mysql_num_rows($literarydevices); if($rows > 0) { mysql_data_seek($literarydevices, 0); $row_literarydevices = mysql_fetch_assoc($literarydevices); } ?> </select> Can anyone offer a reason to why the values are not being stored?
View Replies !
Indented Text List To Array
I'm trying to get a tabbed list into a structured array and can't seem to get it. I'd like the get from this: PHP Code: <?php $contents = array( Â Â Â Â 'Level 1 Item 1', Â Â Â Â 'Level 1 Item 2', Â Â Â Â " ".'Level 1 Item 2 > Level 2 Item 1', Â Â Â Â " ".'Level 1 Item 2 > Level 2 Item 2', Â Â Â Â 'Level 1 Item 3', Â Â Â Â 'Level 1 Item 4', Â Â Â Â " ".'Level 1 Item 4 > Level 2 Item 1', Â Â Â Â " ".'Level 1 Item 4 > Level 2 Item 1 > Level 3 Item 1', Â Â Â Â " ".'Level 1 Item 4 > Level 2 Item 1 > Level 3 Item 2', Â Â Â Â " ".'Level 1 Item 4 > Level 2 Item 1 > Level 3 Item 1 > Level 4 Item 1', Â Â Â Â " ".'Level 1 Item 4 > Level 2 Item 1 > Level 3 Item 1 > Level 4 Item 2', Â Â Â Â 'Level 1 Item 5',.
View Replies !
Dynamic Drop-down List With Array - Question
Can anyone out there give me a pointer regarding creating a dynamically-generated drop-down list connected to an array? And is that question as clear as chocolate spread? Here's what I've got. I'm using PHP and MySQL database. I'm customizing some calendar software, and I want the user to fill in a form by selecting a title from a drop-down list, generated by my MySQL database. However, the program I'm customizing uses arrays, which is where I'm stumped. What do I need to add to this code to make the array of titles(eg "report writing" etc) come from my database, rather than the manually-entered values that you can see here. The field I want to pull from is called com_courses.title array ( "coursetitle", "Course Title:", $EXTRA_SELECTLIST, array ("Report Writing", "Recruitment & Selection", "Presentation Skills", "Essential Telephone Skills", "Time Managememt", "Customer Care", "Other"), 0 ), I hope it's not cheeky to ask this, BTW I bought a book on Programming with PHP and MySQL, but it doesn't answer this question,
View Replies !
Create An Array From A List Of IDs Within A Database Table
I need to create an array from a list of IDs within a database table. The table consists of 3 fileds, a unique ID, a user ID and the last is an int value (item number) eg 1 3 7 2 4 5 3 3 2 etc... How would I go about using this query $query1=mysql_query("SELECT itemnumber FROM table WHERE userid = '{$user}'"); Would i be right in thinking I can use: $array = mysql_fetch_array($query1); to store all the item numbers associated with the user specified in the first query?
View Replies !
Cause Array To List As Separate Rows In MySQL
I want this array to post as separate rows in MySQL instead of one row with the array.... (thanks either way) <input type="checkbox" name="box".$boxId."[]" value="".$fields['boxvalue']."" ".((in_array($fields['boxvalue'],$selectedValue))?"checked":"")."> Code:
View Replies !
List Subscribe Form
trying to make a simple subscribe form for an email list like so... $to = "news-subscribe@mysite.org"; mail($to, "subscribe", "subscribe", "From:$subscribe Reply-To:$subscribe"); but the email list never confirms the subscription by email so can't figure out whether its getting the email or not? nether the subject or body text are necessary, its the address that does the command, any ideas anyone?
View Replies !
Form Entry List
I have a form with one box into which users type a few words (an email address). That entry is emailed to me. I need to copy each entry into one text file automatically so I do not have to copy them manually out of each email one at a time. The result would be one text file with the entries listed down the page, one by one.
View Replies !
Change List Value In Form
I want to have in a form a list element that gives you the opportunity to choose between "taken" and "not taken". At the beginning the list value is on "not taken". What I want know is that when a costumer clicks on the list value taken and then submits the form that then the web page will be updated so that the next visitor who visits the page sees that that item has already been "taken". Code:
View Replies !
PRODUCT LIST FORM
I have a form that loops out a list of products from a mySQL database. beside each product is 2 checkboxes. one is for deleting and another is for selecting a product to go into a storefront. on the second page I have a implode() to seperate each product with commas. then it puts the list into a query and deletes them one by one. my problem is the only way to use a implode is to use $_POST by itself without the element ($_POST['var']) what if the user checks some boxes to put into the storefront and checks some boxes to delete. how can i filter the two so i wont get them mixed up and end up deleting something that probably was suppose to be stored in the storefron.
View Replies !
A Form Menu List
I have a date of birth script on my website and at the moment im faced with typing in about 100 dates ranging from 1900 to 2006 is their any way i could use php to create the range of dates in a form menu list?
View Replies !
Dynamic Form List
I'm trying to get a dropdown menu where the options are made up from entries in my database. Bellow is what I've tried but it only puts the first item in the list and the rest appear as normal text next to the dropdown box. Code:
View Replies !
Array Problem... - Store This List In $_SESSION['liste'];
the user selects 6 numbers in a list I have to store this list in $_SESSION['liste']; (I cant do it differently) the list is stored like that: 34-21-44-32-12-11 (cant do it differently either) what I need to do is to explode the array, get rid of the - , sort the values in ascending order and send them to my table as a string. so in the end I should have: 111221323444 I tried using a variation of laserlight's script (given in a previous post) without success... hope that someone will have time to give me a hand again in telling me what I could change in saberlights script to make it work.
View Replies !
How Do I Find A Word In A Sentence From The List Of Words In An Array?
I have few list of words (needle) I want to find in a sentence (haystack). After a word is found, how would I echo that word? Is there a way to have a multi array so: if the sentence contains word1,word2 or word3 then echo "coding" if the sentence contains word4,word5 or word6 then echo "forums" <?php $title_of_the_item = "This would be the sentence being pulled."; $words_from_title = explode(" ", $title_of_the_item); $word = array("structure", "php", "sentence", "pulled"); if(in_array($word,$words_from_title)){ //even though two words are found in the array, use only 1 } ?>
View Replies !
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:
View Replies !
How To Post A Form To A List Document
I'm not looking to learn alot of PHP right now but i am learning enough to get done what needs to be done. I need to no how to make a list document that gets and posted form from a different document and puts it into a list, . heres my form from my input.htm Code:
View Replies !
Dynamic Form - How To Set Values Of A List
I have a form with a list/menu in it that is populated with records from a database. The items in list#2 are based upon what is selected in list#1. I have been able to use a combination of php and javascript to get it to work, but the javascript reloads the page to get list #2 to refresh - and that clears out any other fields that have been filled in. Instead of javascript being called for the 'onchange' event for list #1, I'd rather it call php when list#1 is changed and so reset the values in list#2. OPTIONS: 1. I thought I could have a php function that is called (i.e. onchange="<?php reload();?>" but I can't figure out how to set the values of the list from within the php function. How to reference form objects with php?
View Replies !
Bad Word List - Email Form
I am trying to limit the spam coming through my email form from the source. Can anyone possible assist me in how to create a script to read from a badwordlist.txt file and check that no bad words occur in the email message body ($message)?
View Replies !
|