logo
down
shadow

How to break zero index comma separated value into individual string in php


How to break zero index comma separated value into individual string in php

By : user2957041
Date : November 22 2020, 03:03 PM
will be helpful for those in need I want to break comma seperated values which are retrieved from database and then put each individual in a string and print it in a for loop only. I am getting the values from database but i am not be able to break values. Below is the code what i have done right till now.Please help to solve my issue. in advance. , Please try to use ',' instead of ', ' in your
code :
explode(', ', $success['subjects']);
explode(',', $success['subjects']);


Share : facebook icon twitter icon
Turning a Comma Separated string into individual rows

Turning a Comma Separated string into individual rows


By : ЯadiCal
Date : March 29 2020, 07:55 AM
This might help you I have a SQL Table like this: , You can use the wonderful recursive functions from SQL Server:
code :
CREATE TABLE Testdata
(
    SomeID INT,
    OtherID INT,
    String VARCHAR(MAX)
)

INSERT Testdata SELECT 1,  9, '18,20,22'
INSERT Testdata SELECT 2,  8, '17,19'
INSERT Testdata SELECT 3,  7, '13,19,20'
INSERT Testdata SELECT 4,  6, ''
INSERT Testdata SELECT 9, 11, '1,2,3,4'
;WITH tmp(SomeID, OtherID, DataItem, String) AS
(
    SELECT
        SomeID,
        OtherID,
        LEFT(String, CHARINDEX(',', String + ',') - 1),
        STUFF(String, 1, CHARINDEX(',', String + ','), '')
    FROM Testdata
    UNION all

    SELECT
        SomeID,
        OtherID,
        LEFT(String, CHARINDEX(',', String + ',') - 1),
        STUFF(String, 1, CHARINDEX(',', String + ','), '')
    FROM tmp
    WHERE
        String > ''
)

SELECT
    SomeID,
    OtherID,
    DataItem
FROM tmp
ORDER BY SomeID
-- OPTION (maxrecursion 0)
-- normally recursion is limited to 100. If you know you have very long
-- strings, uncomment the option
 SomeID | OtherID | DataItem 
--------+---------+----------
 1      | 9       | 18       
 1      | 9       | 20       
 1      | 9       | 22       
 2      | 8       | 17       
 2      | 8       | 19       
 3      | 7       | 13       
 3      | 7       | 19       
 3      | 7       | 20       
 4      | 6       |          
 9      | 11      | 1        
 9      | 11      | 2        
 9      | 11      | 3        
 9      | 11      | 4        
How to transform a comma-separated string to line-break-separated string?

How to transform a comma-separated string to line-break-separated string?


By : Kurt Clauss
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Don't string join, just writeline the colors and next return with join on \n
code :
public static string getcolours()
{
    List<string> colours = new List<string>();
    DBClass db = new DBClass();
    DataTable allcolours = new DataTable();
    allcolours = db.GetTableSP("kt_getcolors");
    for (int i = 0; i < allcolours.Rows.Count; i++)
    {
        string s = allcolours.Rows[i].ItemArray[0].ToString();
        string missingpath = "images/color/" + s + ".jpg";
        if (!FileExists(missingpath))
        {
            colours.Add(s);
        }
    }
    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"F:\test.txt", true))
    {
        foreach(string color in colours)
        {
            file.WriteLine(color);
        }
    }
    return string.Join("\n", colours);;
} 
Extract words from comma-separated string to individual rows

Extract words from comma-separated string to individual rows


By : hvillero
Date : March 29 2020, 07:55 AM
wish helps you This could work, with some limitations. And I am not sure if you need columns to always containt same values (Base on your sample data, this is what it seems to be). I have included a row with VegX, A and Z to illustrate this Hope that helps
code :
--  Get the sample input table
declare     @intable    table
    (RowNumber int, Names varchar(50))
insert into @intable 
values 
(1, 'Veg A, Veg B, Veg C, Veg D'), 
(2, 'Veg A'), 
(3, 'Veg A, Veg B, Veg C'), 
(4, 'Veg X, Veg Y, Veg Z')

-- Limitation : Will work only if list is not greater than 12 vegetables.. If more needed, need to build a query and then execute

-- Step1 : Split the content using string_split 
;with sco as (
select  rownumber, ltrim(Rtrim(Value)) as myvalue
from    @intable
        cross apply string_split(names, ',') t2),
-- Step 2 build col name using dense_rank
sco2 as (
    select  rownumber, myvalue, 'col' + format(dense_rank() over(partition by rownumber order by myvalue), '0') as mycol
    from sco)
-- Final select using PIVOT to put rows in columns
select  * from sco2
PIVOT
(
    min(myvalue)
    FOR mycol in (col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12)) as ptv
SQL - Update table after Turning a Comma Separated string into individual rows

SQL - Update table after Turning a Comma Separated string into individual rows


By : tryan06
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Sample Data
code :
CREATE TABLE Testdata
    (
     SomeID INT,
     OtherID INT,
     String VARCHAR(MAX)
    )
    INSERT Testdata SELECT 1,  9, '18,20,22'
    INSERT Testdata SELECT 2,  8, '17,19'
    INSERT Testdata SELECT 3,  7, '13,19,20'
    INSERT Testdata SELECT 4,  6, ''
    INSERT Testdata SELECT 9, 11, '1,2,3,4'

    CREATE TABLE NewData
    (
      SomeID INT,
      otherID int,
      String VARCHAR(MAX)
    )

    INSERT INTO  NewData (SomeID,OtherID,String)


    Select A.SomeID,OtherID,
    B.* 
    From [dbo].[Testdata] A
    Cross Apply (
    Select RetVal = LTrim(RTrim(B.i.value('(./text())[1]', 'varchar(max)')))
    From  (Select x = Cast('<x>' + replace((Select 
    replace(A.String,',','§§Split§§')
    as [*] For XML Path('')),'§§Split§§','</x><x>')+'</x>' as xml).query('.')) 
    as A 

    Cross Apply x.nodes('x') AS B(i)
    ) B


    Delete  from Testdata
    Insert Testdata (SomeID, OtherID , String)

    select SomeID, OtherID , String from NewData
Turning a Comma Separated string into individual rows in Teradata

Turning a Comma Separated string into individual rows in Teradata


By : user5099697
Date : March 29 2020, 07:55 AM
should help you out This is SQL Server syntax.
In Teradata there's a table UDF named STRTOK_SPLIT_TO_TABLE, e.g.
Related Posts Related Posts :
  • How to add Smarty templating engine to CodeIgniters 3 framework?
  • Am I maxing out possible data insert
  • Redirect to homepage without changing address bar URL
  • What is the best user-Id Value for a MySql "users" table
  • PHP $_COOKIE is only available in one directory
  • php regular expressions documantation
  • cannot import too large sql file to mysql
  • not getting appilcation/json in content-type in header
  • Only the first data display from my database but other shows but not on a table
  • Is it possible to have a print button link as the content of the mail
  • how to extract full mail address in imap php
  • Alternative to output buffering to put eval'd code into a variable
  • how to run wordpress php snippet mysql update command from ssh and/ultimately cron
  • how to get xml tag by name
  • ModSecurity maximum post limits (PCRE limit errors)
  • Call controller/action in event listener
  • How to improve performance of contacting WebService?
  • PHP nest variable in echoed string that contains a HTML tag in the end
  • Multiple Ajax request for PHP framework
  • Debug Info from Moodle Plugin
  • passing variables through page
  • Passing PHP $result data to Javascript
  • cakePHP File Download was not found or not readable
  • batch waiting until script finishes
  • PHP variables and anchors in URL
  • php eTag generation using php
  • How to check whether the array is an Integer or Not?
  • Is it possible to install Doctrine without PEAR or Composer? If so, how?
  • Call view script of (parent) Abstract controller Zend
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org