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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





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 Complete Forum Thread with Replies

Related Forum Messages:
Set An Array = To A Comma Delimited String Of Strings
is there anyway I can set an array = to a comma delimited string of strings and then loop through each of those manipulating the string. help me with the basic code for setting up the array and looping through it.

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 !
Comma Delimited File
I am trying to read comma delimited rows of text. The problem is that
some fields may be encapsulated in "" - particularly the text fields but
not numeric fields.

Is there a simple efficient way to parse the fields with comma but also
strip off the "" encapsulating some of the fields with php?

The problem is the "" encapsulation is optional. Some fields will have
it, some won't.

View Replies !
Statement With Comma Delimited Fields
I'm hacking into my vBulletin forum to use individuals current usernames, passwords, and membergroups to setup a premium portion of my site. I have the following query: PHP Code:

$users = mysql_query("SELECT * FROM user WHERE username='$username' AND membergroupids=ཛྷ'");

With this query my login works for those who have signed up for the premium content on the forum. One problem is if the members join multiple user created member groups, they're membergroupids will be like 32,10,34. I need my query to find if they belong to 32 and if so allow them access. So, if they belong to 32,10,34 then they should be allowed to enter, but if they belong to 10,34 they should not.

View Replies !
Looping Through Comma Delimited String?
I'm wondering how I can loop through a comma delimited string in php?

my string: $string = "12499, 12498, 12497";
though the size will change depending on the query.


View Replies !
Comma Delimited Csv Has Commas Inside Fields
I need to import a CSV file into a database daily. That operation in itself is simple enough but the trouble is that some fields are quoted because they have commas inside them. How do I handle this with my import script?

It would be much better if the CSV was created with all fields quoted or used a different delimited but sadly that is not an option.

View Replies !
Regular Expression For Comma-delimited Pairs
I have a textarea form field for inputting (or pasting) pairs of data.

I need a regular expression pattern to validate each line for the following

double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return

The following comes close, but doesn't check for a carriage return at the
end of each line:

^"([0-9]?)+"([,]s?"([A-Za-z0-9]+)")*$

For example the following would return true:

"1","John"
"2","Paul"
"3","George"
"4","Ringo"

View Replies !
Reading Excel To MySql Or Comma Delimited ...
right direction on how to deal with an xls
flie.

but the only other file I have to work
with is pdf.

I'm not sure, is xls the better of two evils?


View Replies !
Stripping Quotes Out Of A Comma Delimited File?
I have a flat file that I'm trying to stick into a MySQL database. One
record per line, multiple fields per record, and many of them are null
fields which are just double quotes without a space between. It's probably
nothing really major for people who have done this before, but I'm a bit
stumped. The file is comma delimited. Every field is surrounded by double
quotes. I've done quite a bit of searching, on the php site and elsewhere,
but I can't seem to get it to strip the quotes out so I can explode the file
line by line to grab the fields.

View Replies !
Easy Comma-delimited List To Dropdown Box Converter
I was working on a simple converter when I realized that by not setting the id param of the option tag, it wasn't going to send the value of the dropdown box to my php script. I had this to start with: Code:

View Replies !
File Parsing Function For Tab Or Comma Delimited Files
I need a way to parse a file based on the delimitation of either tab or comma. Does anyone know the best way to do this that is the easiest? Also the file I am parsing might have a few empty strings between delimitation. I know about preg_split so if this is the only way could someone provide a link that explains regular expressions because i dont get it.

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 !
Upload Text Delimited Field
I'm trying to use an upload file form: Code:

<input name="upload" type="file">

I want to upload a comma delimited text file that is structured like: ID,Date,Team1,Team1Name,Team1Score,Team2,Team2Name,Team2Score,Detail What I'd like to do is have some PHP (and mySQL) that'd take that comma delimited file and insert it into the database, and if the ID in the file is already in the DB to overwrite it.

View Replies !
Is There A Php Command To Take A Specific Field From A Delimited Line Of Text?
I have a string which is multiple fields delimited by commas.

I would like a php command that says... take the 3rd field for
example.

ie. If MYVARIABLE has the data "hello,there,big,world".

I would like to be able to say, pickup the 3rd field "big" without
knowing the character positions or lengths.

View Replies !
Number Format - Put The Comma In The Field.
Currently, if the user enters a list_price value of 25,000, my program is changing it to 25; if I enter 25000 (w/o the comma), it's displaying OK, but I'd like to be able to put the comma in the field.

What do I need to change/add to accomplish this? Code:

View Replies !
Preg_split - Field Is Seperated By Comma
I have a text file which each field is seperated by comma. And each field can contain either numeric character or non-numeric character(which is
surrounded by a pair of double quotes).

But my problem is: if I seperate the fields using comma, then the address field will be seperated into 2 array elements array, since my address field itself contains comma. Code:

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 !
Seperating Comma Seperated Field Entries
i want to seperate my comma seperated field and replace the comma with a line break when displaying so that url1 , url2 , url3 and so on becomes:

url1
url2
url3
and so on.

I know what to do when i know how many urls, but this number is indefinite.

View Replies !
Create A Delimited Text Array
How can I create a delimited text file to work with this script. I would like to put this first part in a text file and load it into an array so the php script can parse it. Code:

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 Dates To Mysql Date Field
Is there a way to convert a date in this format:

8-7-2002 to fit into a MySQL date field format 2002-08-07.

the 8-7-2002 is a field in which users pick a date from a pop-up calendar in javascript. When I enter that date into the database, i want to convert it to the MySQL date format.....is there a way to convert it?

View Replies !
Looping Thru Array And Creating Comma Sep String
I'm trying to loop through the elements of an array and create a comma separated string of the values, and then trim off the last comma. Here's the code I have which only displays the last element of the array in the string: PHP Code:

View Replies !
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 Replies !
Pull Data From Mysql From A Varchar Field With Comma Seperated Data
I'm trying to pull data from mysql from a varchar field with comma seperated data, like: test, test, test, and so on. when I try to display the data i just get "array" in the input field. what i'm wondering is how can I show the data correctly? I'm a little lost here.

View Replies !
Create An Array From Variable Seperating The Values By Comma?
I have a variable with the following values...

$variable = "3,6,9,12";

How would I create an array from this variable seperating the values by comma?

$array = array($variable);

Above doesnt work, it doesnt split the array in seperate values, it thinks "3,6,9,12" is one value?

View Replies !
Converting Value Of 'email_id ' (varchar Field) In Mysql Database To Ascii Code
I want to use value of 'email_id' (varchar field) in mysql database to covert into respective ascii code so that it can be used for future purpose.a part of my code is given below.can someoone guide me how to do that as I am new to PHP.I ma using PHP5.2 with mysql 5.0 nd IIS 6.0. Code:

View Replies !
Converting One Value In Array To UPPER Case
I am collecting data from the form. Before I put collected data That I got from $_POST['array']) into a MySQL database I want to convert one of the values (let's say value 1 in the array) in the array to upper case. How can it be done? Below is the snippet of my code that I use to put data into a dtabase. Code:

View Replies !
Converting Form Fields Into An Array
I have a form that enters inventory values based on date. Each day has a certain inventory value. Some days of the month have the same inventory values. I have 31 checkboxes, one for each day of the month and the inventory value form field.

I enter the inventory value and then check the days that the inventory value applies to.

When inserting the data into the mysql database, I would like to loop through the days and if a day is checked, then I run the mysql query to insert the data.

How do I convert all the checkboxes into an array or is there a better way to do it?

View Replies !
Selecting Array Rows Based On An Array Of Field=>values
Here's the code i have:

$db = array(); //main array
$db['main'] = array(); //table `main`
$db['main'][] = array('id'=>0,
'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin');
//row
$db['main'][] = array('id'=>1,
'username'=>'bob_smith','userpass'=>'psswrd','userlevel'=>'user');
//row

function trim_value(&$value){
$value = strtolower(trim($value));
}
function fdb_select($fields = "*", $table, $where = false, $limit =
false){
global $db;
$retv = $db[$table];

//LIMIT RESULTS TO FIELDS
if(strrpos($fields, ",") === false){$field=array($fields);}else{$field
= explode(",", $fields);};
array_walk($field, "trim_value");
$all_fields = array_keys($retv[0]);
if($fields == '*'|| is_null($fields)){$field = $all_fields;};
$field = array_uintersect($all_fields, $field, "strcasecmp");
$retvi = array();
foreach($retv as $num =$row){
foreach($row as $fname =$fvalue){
$fname1 = strtolower($fname);
if(in_array($fname1, $field)){
$retvi[$num][$fname]=$fvalue;
};
};
};
//DONE LIMITING TO FIELDS
if($where != false){

//UP TO HERE IT WORKS FINE
//LIMIT TO WHERE CLAUSE
$retvj = array();
foreach($retvi as $num =$row){
//IN THE ROW
foreach($where as $k =$v){
//IF ROW MEETS ALL REQUIREMENTS
if($row[$k] == $v){
$retvj[] = $retvi[$num]; //Keep that row
};
};
};
//DONE LIMITING TO WHERE CLAUSE
};
$retvi = (isset($retvj)) ? $retvj:$retvi;
//SEND A FINAL ASSOCIATIVE ARRAY
return $retvi;
};
print_r(fdb_select("*", "main", array('id'=>"1",
"username"=>"joshfrench")));

the previous code outputs this:

Array
(
[0] =Array
(
[id] =0
[username] =joshfrench
[userpass] =password
[userlevel] =admin
)

[1] =Array
(
[id] =1
[username] =bob_smith
[userpass] =psswrd
[userlevel] =user
)

)

View Replies !
Visibility Matter On Converting Object To Array
i was into array part on tutorial and it says

i'll get an array having keys that from member variable's name

by converting an object to array.

i guessed "i can get public members but not protected, private, static
members"
(just like i got error if i try to access protected, private members
outside of object)

then i wrote a simple code to see how's it going.

################## code #######################
<?php
// for testing, each member of public, protected, private, static
CLASS test {
public $a = 'a'
protected $b = 'b'
private $c = 'c'
static $d = 'd'
}

//converting an object to array
$a = (array)new test();

var_dump($a);
echo '<br>'
/*let's see how it works (it threw not static member cuz it's not in
the object as i guessed. but it prints all other members including
public, protected, private eventhough i called this func outside of
object)*/

//i wanted to try to access by another way and it works too.
foreach($a as $i => $j)
echo "$a : '$i' => '$j'<br>
";

//i tryed to access by the key i saw on result. but it doesn't work at
all.
echo $a[' test c'] . "<br>
";
?>

################## output #######################
array(3) {
["a"]=>
string(1) "a"
[" * b"]=>
string(1) "b"
[" test c"]=>
string(1) "c"
}
<br>$a : 'a' => 'a'<br>
$a : ' * b' => 'b'<br>
$a : ' test c' => 'c'<br>
<br>

#################################################

if i try to access protected, private members directly outside of the
object, i'll get an error.

but by convering the object to array, i can get all member variables.

is it right way? then what about the visibility. i think i can be a
problem.

Is it right way to access object members?(by converting to
array)<<----------------------------- Q1.

anyway i tried to access by typing the key i saw on output ' * b' , '
test c', it didn't work.

while with the key variables i got from 'foreach', it worked.

i think i made a mistake on making the keys.

View Replies !
Exploding An Integer String And Converting It To An Array
I am working on a travel specials management system. The 'specials' table in the db has a resort_id fk to the 'resorts' table to identify what resort the special applies to.

The resort entry in the 'resorts' table has fields for room categories - room_cat_1, room_cat_2, etc. I need to have a field in the 'specials' table that identifies what room categories that the special applies to at the particular resort. Code:

View Replies !
Converting Json Array And Objects Into Php Array And Objects.
I am using the Services_JSON class since we are running PHP 4.3.  I have successfully converted simple arrays from javascript to json to php and then back again in fiddling around with this, but now I am actually trying to do something useful.

In javascript I have built an array of objects like so: ......

View Replies !
More Than One Field In Array?
The script below pulls a variety of data from a table (the same query is used elsewhere), pushing the grouped summary of results of one field to a page. We need to add another field (a description) to the array, at the $tmp_array[] = $row[3] level, so that the array consists of $row[3] and $row[10]. The end result should be: Code:

View Replies !
Form Field To Array
Ok, two questions:

1) I have a mulitple select form field. It is named 'artists[]' and it produces the array artists[$i] correct? now i want to make the array into a single variable named $artists that containes the array in a CSV format with no ending comma.

how do i do that?

2) Is it possible to browse for a directory and pass it though a script as text? not a file, just a directory?

View Replies !
Array To Select Field
I need to echo the contents of an array to a <select> field.
What´s the easiest way to do that?

I could just:

<select name="blaha">
<option>$array[0]</option>
<option>$array[1]</option>
<option>$array[2]</option>
</select>

The problem is that the numbers of "parts" (I don´t know what they are called) in the array is different from time to time, so first I need to check if it´s empty or not, and if it isn´t, echo it.

View Replies !
Recreating Array From SQL Field
I'm trying to recreate an array from a var_export()'ed array stored in
a database, using eval().

Basically I have something this in my database:

array (
0 => 1,
1 => 2,
2 => array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)

If I then read it into a variable:

$stored_array = /*whatever_sql_statements_for_reading_stored_array* /

I would think that something like:

eval('$recreated_array = $store_array');

View Replies !
Validate Field From Array
$ids_to_check = array('rsm' => array(?yHehAAE', ?ter0AAA',
                    ?llhVAAQ', ?lllcAAA', ?lllmAAA',
                    ?llptAAA', ?lltWAAQ', ?lltgAAA',
                    ?lm20AAA', ?lm2EAAQ', ?lm2JAAQ',
                    ?lm2OAAQ', ?lm2TAAQ', ?lm2YAAQ',
                    ?lm2dAAA'), 'fae' => array(?lm2nAAA', ?lm32AAA',
                    ?lm37AAA', ?lm3CAAQ', ?lm3HAAQ',
                    ?lm3gAAA', ?lm3hAAA', ?lm3iAAA',
                    ?lm3jAAA', ?lm3lAAA', ?lm3mAAA',
                    ?lm3nAAA', ?lm3qAAA', ?lm3rAAA',
                    ?lm3vAAA'));

PHP Code: .....

View Replies !
Get Values Of A Field Array
I have this 10 input texboxes made by a FOR Loop. how can I get their input values?

Here are my codes:
Given: Inside a table

for ($i=1;$i<=10;$i++) { ?>
<tr>
<td>
<input name="date_range" id="date_range" type="text" tabindex=&#391;' size=&#3911;' maxlength=&#3911;' readonly value="" > <img src="images/calendar.png" alt="Date From" id="txtDateFromTrigger" align="absmiddle"></slot></td>
<script type="text/javascript">
Calendar.setup (
{
inputField : "date_range", // ID of the input field
ifFormat : "%Y-%m-%d", // the date format
button : "txtDateFromTrigger" // ID of the button
....................

View Replies !
A Tables Field Containing An Array
I am creating a poll/voting feature for my forum and i want to make it so that a user can only vote once per poll. So what i plan to do is store everyone username who was voted in an array and store it in a MySQL table. When someone else votes, i'll extract the array from the database, add the current voters username to the array and then write the array back to the database. Is this possible?

View Replies !
How To Get Field Values In Array
i got database with field - parts, it contains:

metal<br />
plastic<br />
waterproof<br />
rubber


how can i put every line in array as element, so i could echo this field with forech or somethin.. and do

echo "conteiner #1 - $arr_el[0]";
echo "conteiner #2 - $arr_el[1]";
and so on..

and it would print out something like

conteiner #1 - metal
conteiner #2 - plastic
..

View Replies !
Call One Of The Fields Ie $array[field]
If i created an array that holds fields of a table, how could I call one of the fields ie $array[field] if i need the field part to be a variable?

View Replies !
Make An Array With All The Values From The Field
I have a mysql select query and got it in an array

$query = "select persid from reactie";

$result = mysql_query($query);
$query_data = mysql_fetch_array($result);// Haal de gegevens uit de
tabel

NOW I WANT TO ECHO I"T:

echo "$query_data[8]";

But only the query_date[0] is valid. What am i doing wrong? there are many
more values in the table. I want to make an array with all the values from
the field "persid" in the database.

View Replies !
HTML Form Field Value And Php Array
I am creating a html form which has 5 html list menu and menu value get store in array after hitting submit button. The value stores in PHP array and then print on same page and then after re checking the value If i want modification then click the edit button and value re store in the same html form.

Here we are not using the database. If it is possible then please provide me the code and if there is any other solution to this problem them please guide me. for above problem please avoid the java script in php code.

View Replies !
Splitting A Field Into An Array (or Variables)
what I am attempting to do is split a field of comma-separated keywords into an array or maybe some variables or something. Basically I want to make it searchable so that when a user types a keyword, my script returns all the rows that feature that word in their "keywords" field. The row looks like this: Code:

View Replies !
Array Type Field - MySQL
I want multiple users to be able to control one planet. The thing is, I also want users to be able to control multiple planets.

Everything was going fine until I was making the db, and realized I have no clue as to how I'd add an array type of field... see, I got planet id (pid), which is auto_increment. Then I have user id (uid) to connect the planet to the user... or on this case users. Code:

View Replies !
Problem With Field/array Length
I'm having trouble with the length of one field in this array i read/write to a csv-file for my system here at work.

$linecontent[49]     = $article;
$newarticle        = str_pad("".$linecontent[49]."", 10);    
$linecontent[49]     = """.$newarticle.""";

The trouble is that the length of the field [49] differs from line to line allthough I've used str_pad. Isn't that the whole idea about str_pad, or is my code wrong?

View Replies !
Sort 2 Dimensional Array Alphabetically By Second Field In Each Row
Is there an easy way to sort a 2 dimensional array alphabetically by
the second field in each row?

Also, when I use sort() on a two dimensional array, it seems to work a
lot like array_reverse().

View Replies !
How Do You Access An Array In An Included/required Field?
I have a large array that would be messy to include in the file "main.php"
itself and would prefer to include/require it. Say I have the following
line in "main.php":

require_once('/arr.php');

And the "arr.php" file looks something like this:

<?php
array(1)='ok1@Ok.com'
array(2)='ok2@Ok.com'
array(3)='ok3@Ok.com'
array(4)='ok4@Ok.com'
array(5)='ok5@Ok.com'
array(6)='ok6@Ok.com'
array(7)='ok7@Ok.com'
array(8)='ok8@Ok.com'
array(9)='ok9@Ok.com'
array(10)='ok10@Ok.com'
?>

Would I be able to reference the array AS IF I had declared the array in
"main.php"?

View Replies !
Selecting 1 Field From A Multi-Dimensional Array
I want to know how do I select just 1 field from a Multi-Dimensional Array.
I know how to select all the fields, by using the following format:

<?php
foreach($fields as $key => $val){
echo $val;
}

But how can I do a similar thing, but to just select 1 specific field, not all of them?

View Replies !

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