I had a problem where I could not insert data in Although it may have more columns next time, with different names, it looks like Now I am trying to use the code and my The line below is a problem in the form of comments in the code. This is a problem because the name of the column So my question is how will I do this? In addition to this if there is an easy way to all this I am all ears It is a bad solution but it was best that I now I can come up with Edit There is a lot of confusion for me, the whole goal. This makes sense because this database design is useless and it has a complex problem. The column name is actually the value of the question. The rows below them are the answers to those questions, so ultimately this is my goal. I have a In this way I can write an INSERT which will be If more explanation is required then I will add it. First of all, switch to PDO or MySQLi; see big warnings; This is PDO code: You can then add them: But putting different types of data in the same column ... looks like a problem just populate it like a separate table: each time, and clear it after use table because
column < / Code> Names were not correct. They were just columns 1, column 2 etc. Instead of date, address, city etc. I did not design this database and there is no way to make this change for me, so I decided that the
insert below the
column The name of the
line . Now I have a piece of data to link them all together. So now I am creating a
array of all the values in a
array and
line 1 of all column names so that I can add them to one
associative array
id | Column1 | Column2 Column 3 1 | Date | Address City
id | Column1 | Column2 Column 3 | Column 4 Column 5 1 | Apple | Orange | Tomato | Pears | Ken
associated array :
$ col_keys = array (); $ Col_values = array (); $ Column = "SELECT column_name information_schema.column from WHERE table_name = 'mytablename'"; $ Columns_info = "Select * FROM 'mytablename' WHERE 'id' = '1'"; If ($ query_run11 = mysql_query ($ column)) {if (mysql_num_rows ($ query_run11) == faucet) {$ response ["success"] = 0; Echo $ reaction; } And {while ($ line = mysql_fetch_assoc ($ query_run11)) {$ col_keys ['key_name'] = $ line ['column_name']; }}} If ($ query_run12 = mysql_query ($ columns_info)) {if (mysql_num_rows ($ query_run12) == faucet) {$ response ["success"] = 0; Echo $ reaction; } And {while ($ line = mysql_fetch_assoc ($ query_run12)) {$ col_values ['value_name'] = $ line ['column_name']; // PROBLEM}}} $ end = array_combine ($ col_keys, $ col_values); // resonance '& lt; Pre & gt; '; Print_r ($ last); Echo & lt; / Pre & gt;
$ col_values ['value_name'] = $ line ['column_name'];
associated array which looks like this
column1 = & gt; Date2 column & gt; Address column3 = & gt; City ...
06-22-2013 (date of reply) to
column1 Because
column1 = & gt; Date .
$ dbh = new PDO ('mysql: host = localhost; dbname = my_name', $ user, $ pass); $ Stmt = $ dbh- & gt; Query ($ columns_info); $ Result = $ stmt-> Fetch (); $ Col_values = $ Result;
$ final = array_combine ($ col_keys, $ col_values);
+ ------------ + ------- + | Column_id | Name | + ------------ + ------- +
column_id May be 1,2,3 ... with AUTO_INCREMENT
No comments:
Post a Comment