PhpExcel Dynamic Header in first Row - phpexcel

I have below SQL and I want to write field values in first row and rest of the row and values. How do I achieve using PHPEXCEL.
Can someone post full example.
I found so many example how to write fixed rows when you know the field name but without knowing field name I like to print header in first row and rest as values.
$query = "SELECT * FROM uam_user";

Related

How do I populate an empty column in my sql database?

How do I populate an empty column in my sql database?
I have a list that I want in the last column of my database. If I use executemany it just adds rows on the bottom of my database. Is there a way to fill it from the top? The column is currently populated with NULL values.
Just to be clear. I want the first item in the list to be put in the first row and item n on the list to be put into row n.
Thanks in advance
*Always take backup of your database, just incase you want to revert it back to original state.
Each row in your database table should have a unique primary key. As you mentioned you have a list to be uploaded in the last column, I assume you have some kind of relationship that distinguishes which list item goes to which row in the last column of the table.
You an update a single row by simple update syntax as below:
UPDATE table_name
SET last_column = somevalue_from_list
WHERE id = unique_row_id;
If you want to update all the rows with the same value then
UPDATE table_name
SET last_column = one_value_for_all_rows;
Follow the below suggestion only when you are using phpmyadmin to manage your tables:
If you want to update each row with the unique value from the list then my suggestion will be to export your table in csv format, open in excel like software and add your last column values in last column of each row and then import the changed table back to the database.
Hope this help.

Preventing newly added column to become last in order

Is it possible to add a new column to an existing Kusto table somewhere in the middle , I don't want it to become last column in the table. Right now when I am issuing .create-merge table command on an existing table and no matter which order I specify for the new column, it always ends up becoming last column in the table.
You are right and it is also written in the docs:
If the motivation to re-order the column is in query scenarios, you can create a function (view) with the same name of the table that re-order the columns as you like, this will allow existing queries to work uninterrupted and the column order to be adjusted.
If the motivation is the ingestion scenario where column order is significant (such as in CSV ingestion or update policy), the new column should be specified at the end, no way around it.

create empty row in dbgrid

I wanted to insert several lines to database using DBGrid.
on my query, I selected for example:
select * from cust where id='0';
that code will return no record at all so my dbgrid will not show anything but an empty row. Now I wanted to put in data in empty row with new data. However my data needs 2 lines from dbgrid. I wanted dbgrid creates an empty row right after I fill last column in first row. How do I code that? (without inserting the first row data because later I'll insert everything with a seperated button).
thanks!
you can add records in your table with NULLin each column.
For example, suppose the table where the DBGrid is binded to has 4 columns, than you can try this code to add empty records
Query1.InsertRecord([null, null, null, null]);
With this code you can add as many empty records as you like in the DBGrid
That is assuming that the query component you are using supports the InsertRecord method...

SQLite3 - Updating a single column in a multi-column database

I am creating a table that has a total of five columns. DUring the main "create" process, I only have enough data to populate four of the columns. Later in the execution of the program, I have the data for the fifth column. I start performing an "INSERT OR REPLACE". But! I only use the key column and the fifth column in the statement.
When I browse the database, columns two through four are NULL. So, the question is: Is there a way to only update a specific column (including the key) while keeping the existing data in tact?
INSERT OR REPLACE is the wrong statement, as you've discovered. Unless you can provide correct values for all the columns, an UPDATE statement is a better choice. Just update the column.
update your_table_name
set your_column_name = 'New Value'
where your_key_column = 'Something';
In many applications, more caution is called for.
update your_table_name
set your_column_name = 'New Value'
where your_key_column = 'Something'
and your_column_name is null;

Can we insert Multiple check box Values in One Column?

i wan to insert multiple selected checkbox values to be inserted in to one column, can we do this. and if we can do it? please let me know how to do it......
thank you..
You could take all of the values and append them to a stringbuilder and then submit that to your db column
Use a Flags-type enum and store the integer value in the column.
If you want to want to have these 'multiple check boxes' values predefined then create a separate table for it. Otherwise if they are random, then there shouldn't be a problem. Just read them, append in a string and pass it to database.
You can use separator (like $,:,#...) to combine check boxes value and make one string and insert in to column. And when you want to retrieve that value just spilt that string.

Resources