Php - Parsing A String Separated By Semicolon?

Sep 21, 2013

How can I parse this string


into becoming like this

$name = "john";
$phone = "12345"

because I want to save the parameter in one table column, I see joomla using this method to save the menu/article parameter.


Run Multiple Queries Separated By A Semicolon

May 16, 2013

Create Multiple MySQL tables using PHP

run multiple MySQL queries separated by a semicolon (;) in a string via PHP, perhaps with a PHP-function - and how can such a PHP function be coded? The queries MUST be separated with a colon in a string, and there should be no manual edit of that as accepted in other questions since the solution is supposed to handle this format (that's the point).

$multi_query = "INSERT INTO `stuff_5_firm` (firm_id, firmname) VALUES (0, 'Hey LTD');
INSERT INTO `stuff_6_invoice` (invoice_id, firm_id, amount) VALUES (0, 0, 500);
INSERT INTO `stuff_7_order` (order_id, firm_id, when) VALUES (0, 0, '2018-05-05'); ";

View 1 Replies View Related

Java - Can Execute Queries Separated By Semicolon In Jdbc 5

Aug 29, 2013

My jdbc driver for mysql db is of version 5.1.25.

I want to execute sql query like so:

statement.execute("select fullName from user where user_id=1; select fullName from user where user_id=2");

And I always receive exception:

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select fullName from user where user_id=2' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(


BUT when I run this same query(separated by semicolon) from command line it works perfectly and outputs two tables as expected.

View 3 Replies View Related

Parsing A String And Inserting?

May 23, 2012

I would like to parse a string and insert into a table. The string contains a commas numbers and x's. The commas indicate a null column and the x indicates a non null column. The number will indicate a new row.If there is no update on that row then the string will continue to the next number (see example of string below).

I have been researching commands such as substring, substring index, locate, etc. I also got into a isnumeric function since sql doesn't have an 'is numeric' built in to try and figure out where the next row starts.

Example String: '1,,x,,2,3,,x,x,10'

So this string means and will have to insert into a table like so:

col1 col2 col3 col4 col5
Row 1 null null x null null
Row 2 null null null null null
Row 3 null null x x null
Row 10 null null null null null

I am having the hardest time interpreting the string and receive the string from a place where I couldn't manipulate the string itself.

View 7 Replies View Related

Getting Value From Comma Separated String?

Apr 7, 2010

How to get value between third and fourth occurrence of the string. Example string '1,22,3,45,67,78' How to get 45. Any function in MySQL to get the position of the nth occurrence in the string?

View 2 Replies View Related

Replace Value Of Comma Separated String?

Jun 9, 2010

I have mysql table and i have a fieldĀ  which holds value something like sometimes 65, sometimes 65,34, sometimes 65,34,76 and so on. All i need is that i have to match certain value in these comma separated fields [finding i know, we use FIND_IN_SETS], but my problem is i have to find particular value and replace with another

For instance, i have to search 76 and its found in 65,34,76. Now i have to replace this 76 with 67 to make our set look like 65,34,67.

I hope my query is clear, can any body show me the way to achieve this with mysql?

View 5 Replies View Related

How To Loop Through A Comma Separated String

May 22, 2012

How can i loop through comma separated string in MYSQL.

This is what i want

select exp from expertise where user_name = 'userName';
if exp != null then
INSERT into table T1(exp1) VALUES(exp)

How can i do this ?

View 1 Replies View Related

Selection From String Separated By Commas

Nov 3, 2012

I have this:

$string = "battery,lighter,phone";

I have a table users that has each user's tags.How is it possible to select using sql where tags = $string and where email = '$usermail' ; I just want to retrieve data based on user email and user stored tags that are separated by comma in the table like the above string

View 2 Replies View Related

Using String As Comma Separated Query

Jun 19, 2012

I'm trying to use a comma separated string as part of a query in a stored procedure but can't get it to work. I want the string to be: 'db1','db2','db3'..This is an example of the procedure (I've omitted lots of code for ease of reading):

CREATE PROCEDURE test(taskId int)
declare done int default false;
declare ignore_db varchar(1024);
declare cur1 cursor for select schema_name from information_schema.schemata where schema_name not in (ignore_db);
declare continue handler for not found set done = true;

select value into ignore_db from dbw_parameters where upper(name)=upper('ignore db') and task_id = taskID;

select schema_name from information_schema.schemata where schema_name not in (ignore_db); end;

I've tried:

set ignore_db=concat(''',replace(ignore_db,',','',''),''');

but it just sees the result ('db1','db2','db3') as one string. I need it to treat the string as multiple databases.

View 1 Replies View Related

Comma Separated String Comparison In Query?

Feb 18, 2013

I want to search countries from a table as given below:

| id | country
| 1 | US
| 2 | US,IN,UK
| 3 | US,NZ
| 4 | AUS

How I perform sql query to get all records containing a country = 'US' with additional comma separated countries?

View 6 Replies View Related

Converting Comma Separated String To A List

Oct 6, 2012

I am getting the results like ali,aliiii,asd by echoing $row['GROUP_CONCAT(mem_name)'];.How can I echo them like a list so that I can add anchor tag on click functions etc.i have the query

SELECT cat_id, GROUP_CONCAT(mem_name)
FROM o_newcatmem GROUP BY cat_id

I want the resuts to b displayed like this:


View 3 Replies View Related

Finding Exact Value From A Comma Separated String In PHP?

Sep 24, 2012

I have a product table which contains a field called 'categories' to save product related category ids as comma separated values. I am using regexp to search products from a category.

Assume there is record containing 4,24,1,31 my expression is,

..WHERE categories REGEXP ',?4,?'

but this returns both product of category 4 and 24

I just need to display only category 4.

View 1 Replies View Related

Select All Where Field Contains String Separated By Comma?

Aug 27, 2012

I have a field called 'tags' containing a comma delimited list of tags, such as:

ios, ios development, freelance, new_project

I would like to query the field to check to see if the value 'ios' is in the comma delimited list.

View 3 Replies View Related

How To Compare Two Comma-separated String Lists

Aug 13, 2012

I used a Java method called 'containsAll()' to check if ArrayLists have common content.

Let's say I have a list A (one row), and several other lists in a MySQL table (in column 'name', row by row). All lists consist of comma-separated Strings (at least one String in a list) - names or whatever.

Now, I want to check if all Strings in list A can be found in any of the rows in column 'name'. The result set should show all the rows in 'name' that match, that includes rows/lists must have all Strings in list A, and can have additional Strings.

Example I

A: 'Mr.T'

'Hannibal','Face','Murdock','Mr.T','Donald Duck'
'Face','Donald Duck'
'Superman','Chuck Norris','Mr.T'

Result set: 'Hannibal','Face','Murdock','Mr.T','Donald Duck' -AND-
'Superman',Chuck Norris','Mr.T'

Example II

A: 'Rocky', 'Mr.T', 'Apollo'

'Hannibal','Face','Murdock','Donald Duck','Superman','Mr.T'
'Apollo', 'Superman','Hannibal','Rocky','Mr.T','Chuck Norris'
'Rocky','Mr.T','Apollo','Chuck Norris'

Result set: 'Apollo', 'Superman','Hannibal','Rocky','Mr.T','Chuck Norris' -AND-
'Rocky','Mr.T','Apollo','Cuck Norris'

I wonder if one can carry out those results using a MySQL query.

View 2 Replies View Related

Search Comma Separated Column For Exact Given String

Jun 17, 2011

I am trying to write a query string to search a column that contains a comma separated list of strings. for example for the following records:

1-------------test1 test2 test3,test2,test3
2-------------test1 test2,test4
3-------------test1 test222

So if I am searching for "test1 test2" the query should return record #2 only I am using the following regexp which filters out records similar to #3 but it still returns both number 1 and 2.

SELECT * FROM table1 WHERE column2 REGEXP '[[:<:]]test1 test2[[:>:]]'")

View 4 Replies View Related

Convert Resulted Row From Query To Comma Separated String?

Aug 1, 2012

I want to covert the resulted row from select query into comma separated string. I have table in which there are 153 columns. the select query is like as follow

SELECT * FROM mytable where id = 3

I want all the resulted 153 columns of a row to comma separated string. Is there any trick in MySql ?

View 2 Replies View Related

Php - Implode Array Into Comma Separated String From Query?

Jul 22, 2012

For the last 1 1/2 days I've been trying to store 16 row id's into a string and separate each id with a comma. The array I am getting is from MySQL. The error I am getting is "implode() function:passed invalid arguments"

while($row = mysql_fetch_row($result))


View 1 Replies View Related

Query Finding Values In Comma Separated String

Jan 19, 2013

Possible Duplicate: MySQL query finding values in a comma separated string

If i use g.questions (which is a comma seperated varchar list), this only outputs the first id. But if I manually types in "1,2,3,4" instead of g.questions, I get what I expect...

SELECT FROM `questions` q
ON = 1
WHERE IN (g.questions)

View 1 Replies View Related

Regex - Split Comma Separated String Into Temp Table

Aug 6, 2012

Can you parse a comma separated string into a temp table in MySQL using RegEx?

'1|2|5|6' into temp table with 4 rows.

View 2 Replies View Related

Php - Performance Reason To Store IDs As Comma Separated String In RDMS?

Jan 22, 2013

I have been working on a couple of PHP/MySQL projects where all relationships are stored as comma separated strings.

For example a common relationship would be like

(in psuedocode)

table people
id - integer
name - string
age - integer
teams - string (CSV OF integers, ex '1,3,9,21')
table teams
name - String
id - integer

managing relationships becomes a hassle.

To get all teams for a person:

$person = 'SELECT * FROM People WHERE id= x';

then in php I have been doing something like

$person['teams'] = SELECT * FROM teams WHERE id IN ($person['teams']);

as I was writing this i realized i could probably combine them in a mysql query, something like:

select,, people.teams, from people JOIN teams ON FIND_IN_SET(, people.teams) where

with this type of setup I find myself using FIND_IN_SET, Is there a performance benefit to creating relationships like this?

In my experiences so far FIND_IN_SET has usually been doing a full table scan. If there is no performance benefit, in which instances is it beneficial to using a comma seperated list of integers? It seems that mysql designers had something in mind when creating FIND_IN_SET.

View 2 Replies View Related

Insert Loop Using Single String Of Text Of Names Separated By Commas

Dec 27, 2011

I need a php function that will take an undertermined very long list of names as a single text string that are seperated by commas, e.g. "john,mary,ken,mark,..."

loop through and insert each of the names as a new table row. When all the names have been inserted the loop ends.

View 1 Replies View Related

Stored Procedure Utilizing Comma Separated String As Variable Input

Sep 17, 2012

I have created my first stored procdure (nothing fancy) however im running into an issue.

I want to give it a string input such as 1,2,3,4,5 then it does a simple SELECT * FROM [TABLE] WHERE EAN IN (VAR);

So the stored proc looks like this:

-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
CREATE PROCEDURE `moments`.`new_procedure`(IN var1 VARCHAR(255))

Im am trying to execute it like such:


call moments.new_procedure('5045318357397')

Does Not Work

call moments.new_procedure('5045318357397,5045318357427');

This executes but doesnt not bring back any results. Is it classing the second statement as a string so its doing this:

select * from moments.PRODUCT WHERE EAN IN ('5045318357397,5045318357427')

and not this:

select * from moments.PRODUCT WHERE EAN IN ('5045318357397','5045318357427')

How do i have to format the input in the execute query to get it to take a comma separated string as an input?

View 2 Replies View Related

String - Query For Selecting Most Common Substrings Separated By Whitespace In A Column?

Oct 17, 2012

I have a MySQL database of recipes. One of the columns, NAME, is a varchar(255). Each NAME can be multiple words (e.g., "Chocolate Chip Cookies" and "Oatmeal Cookies").

I'm looking for a way to efficiently parse the recipe names into individual words, then return a list of the most common words. So, given the two recipes above, the query would return:

cookies, 2
chocolate, 1
chip, 1
oatmeal, 1

Is there an efficient way to do this? I could query all the results, split each recipe name into words, then build a data structure to do this outside the database. Alternatively, I could split the strings up ahead of time and build a table.

I guess what I am really hoping for is to leverage the database to do this faster (like with an index). I don't know if that's possible with a single query.So, am I stuck building a table ahead of time? Or can this be done efficiently with a single query?

View 1 Replies View Related

Set Variable Without Using A Semicolon?

Feb 8, 2013

getting the ranking of each person by score, is there a way of declaring the var without using a semicolon? I found one way of declaring from within the query but I couldn't get it to work when using a sub-query like that below:

SET @rank := 0;


View 2 Replies View Related

PHP PDO Prepared Statement Semicolon

Jan 3, 2013

I recently had an issue that was similar to the user's at Why does PDO:: last Insert Id return 0?. Like that user, my problem was solved by removing a semicolon from the end of a PDO prepared statement.

Why prepared statements like in the post above should not have semicolons to terminate them. I've used many PDO prepared statements with semicolons and never had problems until a few days ago. I can't find anything in the PDO documentation about semicolon usage, so I'm confused about whether there's an underlying principle about whether or not to use them. Is it always a bad idea to use semicolons in prepared statements? If so, why?

View 2 Replies View Related

Form Legal Statement Without Using Semicolon?

Feb 8, 2013

I am starting to learn SQL using MySQL and I got my hands on book "SQL for MySQL Developers: A Comprehensive Tutorial and Reference".

Why the author doesn't place semicolons ; at the end of the statements?

Can you form legal statement in MySQL without using semicolon?

Here is an example pulled right from the book (p.45)
CREATE DATABASE TENNIS. Of course, MySQL shell responds by ->.

View 1 Replies View Related

Searching Comma Separated Database Field With Comma Separated User Input?

Oct 10, 2012

I have a data stored as comma separated in the database field. Like say in a field colors there are following rows.

red,blue, green
blue, white, purple, pink
yellow, khaki, maroon, orange
gray, lemon, black, brown

Next user has a textbox in a html form, where he enters a colors in a comma separated form. I want to search the database to return records matching his input. For example.

If I enter red, purple, orange, then the query should return three rows because first row has red, second row has purple and third has orange.

I m not getting the way to easier than breaking the user inputs into array and looping through each colors and search the database to get results. Is there any easier way to do this?

Edit:I know storing data in comma separated form is not a good practice but I m working on a updates on application which was made by other programmer. And at this stage I cannot afford to change table structures.

View 2 Replies View Related

Parsing Out Underscore In PHP?

May 21, 2013

I have a script that Im pulling data from a form when I do var_dump($_POST) I get

array(2) { ["objectName"]=> string(7) "TestOBJ" ["Object_Class"]=> string(12) "Object Class" }

thats fine except I want the "Object_Class" to be "Object Class" Because Im trying to match it with another string with the same value but wont match because of the underscore. How do I remove it?

View 3 Replies View Related

Php - Parsing A Very Big File Into DB?

Feb 6, 2013

i have a task where i need to parse an extremely big file and write the results into a mysql database. "extremely big" means we are talking about 1.4GB of sort-of-CSV data, totalling in approx 10 million lines of text.

Thing is not "HOW" to do it, but how to do it FAST. my first approach was to just do it in php without any speed optimization and then let it run for a few days until it's done. unfortunately, it's been running for 48 hours straight right now and has processed only 2% of the total file. therefore, that's not an option.

the file format is as follows:


where the amount of comma separated numbers following the ":" can be 0-1000. the example dataset has to go into a table as follows:

| A | 1 |
| A | 2 |

so right now, i did it like this:

$fh = fopen("file.txt", "r");
$line = ""; // buffer for the data
$i = 0; // line counter
$start = time(); // benchmark
while($line = fgets($fh))


View 5 Replies View Related

XML Parsing In PHP Not Working?

Nov 9, 2012

I thought that I was properly creating an xml document in my php script from a mysql query, but I am not getting an xml document in return (with no php errors) even though the mysql query works!

$result = $mysqli->query($sql);
if ($result) { //this query works, but no xml document produced as a result
$d = new DOMDocument();
$books = $d->createElement('hey');
$hey->setAttribute('check','The Adventures of Tom Sawyer');
echo $d->saveXML();

View 1 Replies View Related

Parsing XML In A Text Field?

Aug 23, 2010

I have a text field with the following XML:

<xml><progress module="1" status="started" /><progress module="2" status="" /><progress module="3" status="" /><progress module="4" status="started" /><progress module="5" status="" /><progress module="6" status="" /><progress module="7" status="" /><progress module="8" status="" /><progress module="9" status="" /><progress module="10" status="started" /></xml>

I see that in Mysql 5.1 I may have been able to use the ExtractValue function but I am using 5.0.51a of the Mysql server and I don't think it is available in this version.

I want to get to the values within the XML and for each module/status combination. I want a new row in the result set so that I can put the data into two column in a new table.

View 3 Replies View Related

Copyrights 2005-15, All rights reserved