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




Comma Separated Values


What i've done is when the user enters the client list separated by commas..... this works, but I need to know how to warn the user when they have enter the client list with no commas.

Is there some sort of function which does this or is it a regular expression thing??




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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 ....

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 )

Comma Separated Text Files
A client has requested that I make a php app which takes an uploaded image, reads the values and enters them into a database. I've made the upload script which works fine, and the script which enters the values into the database, the only thing left now is how do I make PHP read the file and extract the values? The file is a text file, each field comma separated.

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

Count The Value Separated Through Explode Function
Currently i'm using an explode function to separate the value from a variable...

For Example,
$var1='username,user_type,filetoload'
$var2=explode(",",$var1);

So from here i can extract these 3 values separately...

$extract1=$var2[0];
$extract2=$var2[1];
$extract3=$var2[2];

My question is, how do I want to count that this explode function has extracted 3 values? maybe from the variable $var1='username,user_type,filetoload'
is it possible that i know $var1 contains 3 values ..?

Inputting Integers Separated By Comma's
I have a script which is suppose to UPDATE a user in the database depending on which button they pressed on the previous page. But it doesn't seem to be running the UPDATE query at all. Code:

Regular Expression, Validate A List Of Numbers Separated
I need a regular expression that validate a list of numbers separated
by "-" , numbers can not be greater than 999
Valid examples
0
12-455-01
1-9
125-32-155-45-45
Invalid examples
-1
45-
1-45665456-4
12-45-
-
.......

Comma Seperator
I have numbers retrieved from database which is quite big. Is it possible to give a comma seperator in the sql query or otherwise
how can I format with a thousand comma separator?

Deleting Last Comma
The code below displays pet names like so:

Fido, Bowser, Kittycat, Spot,

and I want to delete only the last comma. I tried 'substr' and 'rtrim' and both of those delete the space and comma between each name, not just the last name as I'd like, so I end up with:
Fido,Bowser,Kittycat,Spot,

How would I delete only the last comma, so that it is this instead?
Fido, Bowser, Kittycat, Spot

Even with trim and substr, I end up with:

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?

Convert Number To One With A Comma
How can I convert "2000" to "2,000?"

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?

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.

How To Instert Comma Into Number?
I am having users submit large numbers into a form, and when those values are returned to them later I want to have the commas in the correct places. ie. 123456.00 changes to 123,456.00. Is there a function that does this conversion? Also, how would I ensure that the number is always displayed with 2 decimal places, ie. 123 changes to 123.00, but 123.00 remains 123.00.

Strip Comma From Number
i have a number 1,553.00 i need to remove the comma and store the value? any ideas?

Breaking Up A Comma Seperated List
i have a list seperated by commas: 1. 3. 5. 7. 9 actually is a varible

$members ="1, 3, 5, 7, 9"; what would be the best way to break that up to insert the values into a table in a loop.

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

Seperator Instead Of A Comma For Listed Items In DB?
I'm making a recipe database, and need to have DB fields in mySQL that
will have lists of values that would get sent to an array to be worked
on.

I anticipate that at times a comma will need to be used in the value
itself. So, what's a commonly used symbol or something that people tend
to use as a separator of a list that would then be used in the split()
function to send the elements into an array?

How To Check If It's The Last Result And Remove Comma
I am wondering if anyone could help. I have a loop that displays my results and places a comma after each. The problem is that when the last result is displayed, it shows the comma.

Example:
for loop{
echo $row['test'].', ';

}

displays...  test1, test2, test3,

Notice after test3, there is still a comma? How do I remove it and have it display... test1, test2, test3

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: ...

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.

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"

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:

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?


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.

Seperate Links From Comma Seperated Value In A Databse
I have a value which is $keywords in my database The key words are separated by commas, like:  fun, funny, exciting, weird I want to make each of those keywords link to "link.php" I can only get them all to be one link, how would I make them each into seperate links.

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:

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?

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??

How To Remove "comma, Full Stop" From A Sentence
I have sentences as follow:

$quote[1] = "To be or not to be, that is the question.";
$quote[2] = "Love looks not with the eyes, but with the mind.";
$quote[3] = "Love all, trust a few. Do wrong to none.";

now I would like to do the following,

1) for each quote[$i], remove all ","(comma) or "."(full stop)...does anyone know how? I have the following code but it does not work. What should I write in $patterns?

for ($i=1; $i<4; $i++)
{
$quote[$i] = strtolower($quote[$i]);
echo "$quote[$i]<BR>";
$pieces = explode(" ", $quote[$i]);
for ($j=0; $j< (count($pieces)); $j++)
{
echo "$pieces[$j] ";
$patterns = ".";
$replacement = "";
print preg_replace($patterns, $replacement, $string);
echo "$pieces[$j] <BR>";
}
}

2) also, I would like to count a) number of frequecy of each term (e.g. "to" has a frequency of 2 in qoute[1]) and b) number of frequency for all three quotes (i.e. "to" has frequency = 3)

but I have no idea how? can anyone please give me an idea?

Assigning Values With Other Values
Say one has an array like such:

array("lang=english", "nomusic=true", "name=Fred", "menu=false");

Is there a function in which I input the array and it makes all the things into variables with the other things as the content like:

$lang="english";
$nomusic="true";
$name="fred";
$menu="false";


Set Values Once
let say that i want to allow someone (the site admin maybe) to chose
certain configuration values, for instance

* number of products per page
* picture widht
* back color
....

Right now, i just have all those info in a php page, so it can't be
modified
$number of products_per_page = 20;
$picture_widht = 2;
$back_color = #FFFFFF;

I could keep this info in the database, but i should read it every time
a page is rendered... (open connection, query, close conn)

What would be the best way to do what i'm need? Is there any chance to
"read once, keep value for ever" ?

Checkbox Values
Basically, I have 2 checkbox's which are printed out for each record within my table. On the next form, each checkbox is tested for being "checked" and the database is updated accordingly.

This is fine. My problem is that I dont want users to be able to select both check-box's at the same time. After talking to "andnaess" on an earlier post and doing some reading, I decided upon using some javascript to do what i wanted.

I have found a script which does exactly what i want, and i am now incorporating it into my original php script.

I am having problems assigning a name and value variable with an array to my checkbox's. Is this possible, or have i got the wrong idea?

Combo Box Values
I have values in a combo box where datas are coming
loaded dynamically. When an user selects a particular value and press search, even after refreshing the page, I want to keep the value same as the user selects. For example suppose if I selects
value PHP from combo box, after submitting the combo box should
value highlighted must be PHP. IS there any way I can do this?

Reading Url Values
I am able to pass values to the URL as this shows. I can get the id value and select data from mysql, but I cannot access the ln value. I have use various combos and acannot get it to read the ln value and display it. What am I doing or not doing? I have used get, post and result:

$id=$_GET[id];
$ln=$_POST[ln];
echo $_RESULT[ln]

Echo Certain Values Only
I'm creating a table that has 7 columns. In the first column, I'd like to show My_SQL data. The data contains multiple fields, but there is one that matters most right now.

Right now, I show this data with:

<?php echo $row_UserData['Number'];?>

However, I only want to echo this value if another value of the same row ($row_UserData['Code']) equals a certain number.

How would I write a conditional statement like this?

2 Values In A Loop
In a guestbook the im building, I want to set the <tr> bgcolor in a difrent color each msg (the same effect is also here in these forums).The code is a while loop (to get mysql results). How can I do it ?

Monetary Values
What is the best way to remove all characters except digits from a string? ie: I may have a value: '$4,000.00' but all I want is 4000

Values From A Form
I have a form (search.html) that has 1 textbox and 3 listboxes. When I submit this form to a php file (search_res.php), I am using $HTTP_POST_VARS to get the values which is fine.

But then in my php file(search_res.php) I again have a listbox with 2 options. When I choose either one of these options to display the search results either by "Price" or "Name" I lose the values of the main form (search.html). How can I keep these values from the main form in my search_res.php page?

How Do You Add Values In Rows Together
I am using the following code to take records out of a Mysql database and display them on an HTML form. $myrow[8] is a number. At the bottom of the table, I want to display the sum of all the $myrow[8] values added together. Code:

Return Values
I have an idea about returning variables.

in 1st page, there's variable "x1". it's action page is B.
So, I can use "x1" in B.

$x11 = (int)$_POST['x1'];

B's action page is C

In that case, I want to use "x1" in C.
So, can I save "x1" in B and use it in C?

for exmaple, can I use following commend in C?

$x22 = (int)$_POST['x11'];

Adding Different Values
How can I do If I need to add some values, I am using LEFT Join and I am displaying some lists There is my code: PHP Code:

Selecting MAX Values
I have a SELECT statement where I use numerous GROUP functions, namely: SUM, MAX and COUNT to query and combine various elements of a table. My question lies around the MAX() function. The field which I am querying for the MAX function is a TINYINT field named HS with numbers ranging anywhere from 0 to 375. However, there is a second TINYINT field named NO which is also tied to it.

Basically I would like to add a "*" to the end of the HS field if the NO field is set to 1. If it is set to 0 I would just like it to display the number in the HS field alone. Is it somehow possible to select the NO field of the specific MAX value in the query? If that can be done then I can combine it when writing my php.

Compare Values From CSV.....
I have a CSV file which contains data from the search engines, which includes search engine, keyword, number of applicants and number of visits.

However in some cases there is repitition however I want to merge those figures together.

An example of what I mean....

Array (add More Values To The End)
I have an array. I wan to add more values to the end of the array. how would i go about doing this. my current code does not work. PHP Code:

Getting Values From A File
I have a file with content like:

John|10|5|7
Alec|22|9|31
Mike|23|42|1

And I can retrieve all the values using explode and a loop. But for what I'm wanting to do is be able to get the values for one particular line rather than the entire. So how can I retrieve the values for one particular line?

Get Values From Textfield
as I am new to PHP my question is related to pure basics. I wrote
simple PHP file for automated mail sending. It sends, of course, mail
with fixed text but I need "mail()" function to retrieve string values
from textfield controls in Dreamweaver instead of fixed string values.

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:

SSL - No $_POST Values
The problem I had was sending posted data to a SSL secure Apache server and when getting the values using $_POST they were empty.

The cause of the problem can be found here http://bugs.php.net/bug.php?id=18759&edit=1
It seems that having enctype="multipart/form-data" in the form tag was causing the problem.


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