Thursday 15 May 2014

mysql - query for or change column name in php? -


Let me remove a way to create an insert statement for a in PHP Need SQL db and I'm having trouble understanding the logic I convergence statement I will get from the data that I'm getting in the JSON . Includes questions and answers in the JSON The table in which I am inserting them is the problem on the front end (the website) contains column names that represent the questions and it looks like this .

  Date | Address City | Zip   

Now the problem is in the database that these names are not released. Column names are only columns 1 column 2 etc. It looks like

  column1 | Column2. Column 3 Column 4   

One more thing - when such a table is created then it will have different values, so I can not work hard to relate. Apart from this, these tables are made from importing Excel spreadsheets from front end (website). So I came up with a line of line 1 and a duplicate; 2 spreadsheets have so much that now when you import them the database looks like this

  id | Column1 Column2. Column 3 Column 4 1 | Date | Address City | Zip   

So now I have some context for those values ​​that will need to be inserted. Now there will be next steps involved.

  1. Depending on the data in row 1 or , the name of the column changes in data in column 1 of the column name.
  2. Enter the data in the correct column based on the query

    So in summary I can not insert the answer in the right column that represents the question without the correct information. I personally think that changing the column name to PHP would be a better option although I am very new to PHP and SQL It is also unaware that it is possible. Any help is appreciated

    edit

    To give a slightly better understanding of this problem, I currently use PHP I am posting.

      $ json = secure ($ _ POST ['evaluation']); / * $ Json = '{"Info": ["Date: 6-22-13", "Phone Number: (555) 555-5555", "Address: 304 N. Scott'sthithad RD.", "City: SCOTTSDALE" , "Zip: 85251", "state: ag"]} '; * / $ Data = json_decode ($ json, true); $ Archive = array (); Forex Currency ($ data ['info'] as $ piece) {$ info = explode (':', $ piece); $ Collection [] = array ('question' = & gt; $ info [0], 'answer' => $ info [1]); } Echo '& lt; Pre & gt; '; Print_r ($ archive); Echo '& lt; / Pre & gt;  

    The following should create an associative array that maps column names to column numbers In database schema:

      $ stmt = $ db- & gt; Prepare ('Column 1, Column 2, Column 3, ... from table where id = 1' is selected); $ Result = $ stmt-> carry about (); $ Data = $ result-> Get (PDO :: FETCH_ASSOC); $ Col_map = array_flip ($ data);   

    You can use it when preparing a database's future query.

    If you do not know how many columns you have, you can:

      $ stmt = $ db- & gt; Prepare ('Select from table * where id = 1'); $ Result = $ stmt-> carry about (); $ Data = $ result-> Get (PDO :: FETCH_ASSOC); Not set ($ data ['id']); // Remove the `id` column, which does not conform to the column N pattern $ col_map = array_flip ($ data);    

No comments:

Post a Comment