I have a hurdle I need to try to overcome. I have a very large database I need to display in separate little excel tables on a website using html.
I know the structure of how to show an excel table on html code as well as the data inside each cell, but my tables I need to be created will vary in number of rows based on the number of columns of a row of data.
As an example one row with a unique primary key has 18 columns that need to be displayed as column 1 = cell A1, column 2 = cell B1, column 3 = cell A2, column 4 = B2, column 5 = A3.... etc. In the end it will be 9 cells tall and 2 cells wide.
The next table will have 26 columns, the next would have 6 columns... etc.
I think I need to send a query to my mysql database to ask how many columns are in the current queried row, then use that result as variable to build each table to an appropriate size?
I am totally lost at how to approach this. Maybe I need some sub script to run to build each table data string before making it html?
Help!
Related
I have a MySQL database with 40 columns (int, float, text, enum, timestamp) and about 1 million rows. When I add a new data array of about 1000 rows with PHP, i need to check the database for existing rows with the exact same data before I insert a new row. What's the best way to do that?
I've been having an issue for days now and have hit a brick wall. Firstly, as the title suggests I have been working to import CSV files to a SQL database.
To be more specific, this is done through PHP scripts on the server and through MySQL into the DB.
I currently have around 30 CSV files (this number is projected to increase) which are updated daily, then a cron script is triggered once per day to update the new data. It loads the file through LOAD DATA INFILE. All of this works perfectly.
The problem is:
Each CSV file contains a different column count. The column count ranges between 50-56 columns. The data I am storing in this collective database only requires the first 8 columns. I already know how to skip individual columns using #dummy thanks to the following Q&A: How to skip columns in CSV file when importing into MySQL table using LOAD DATA INFILE?
However, as the dummy count will not always be the same due to the different column counts, I was wondering if there was a way to get the data from columns 1-8 then ignore all after regardless of column count?
A rather rough patch up would be to first read the beginning line in php, to count columns by commas. Then knowing the amount, subtract 8 and generate the sql command now knowing how many columns you need to ignore.
Just include the eight columns to populate and it will us the first eight from the CSV row:
LOAD DATA INFILE 'file.txt' INTO TABLE t1 (c1, c2, c3, c4, c5, c6, c7, c8)
I have some data in a MYSQL database table that I need to "print" in a HTML web page, but I need that this information be shown dynamically in a 3 row and a maximum 12 column table.
Each column must show three sets of information, that will be displayed in each row, like the table below.
Is there a way to do this using PHP and/or HTML?
Thanks for the help
Suppose I have to write data a Microsoft Excel Workbook, I need to create a table with 5 rows and 4 columns, now in row 3 and column 4, I want to create a table with 3 column and 4 rows.
Using laravel-excel how can I achieve this? I have created the main table, but don't know how to create the inner table. Is it possible ?
I am setting up an uploader (using php) for my client where they can select a CSV (in a pre-determined format) on their machine to upload. The CSV will likely have 4000-5000 rows. Php will process the file by reading each line of the CSV and inserting it directly into the DB table. That part is easy.
However, ideally before appending this data to the database table, I'd like to review 3 of the columns (A, B, and C) and check to see if I already have a matching combo of those 3 fields in the table AND IF SO I would rather UPDATE that row rather than appending. If I DO NOT have a matching combo of those 3 columns I want to go ahead and INSERT the row, appending the data to the table.
My first thought is that I could make columns A, B, and C a unique index in my table and then just INSERT every row, detect a 'failed' INSERT (due to the restriction of my unique index) somehow and then make the update. Seems that this method could be more efficient than having to make a separate SELECT query for each row just to see if I have a matching combo already in my table.
A third approach may be to simply append EVERYTHING, using no MySQL unique index and then only grab the latest unique combo when the client later queries that table. However I am trying to avoid having a ton of useless data in that table.
Thoughts on best practices or clever approaches?
If you make the 3 columns the unique id, you can do an INSERT with ON DUPLICATE KEY.
INSERT INTO table (a,b,c,d,e,f) VALUES (1,2,3,5,6,7)
ON DUPLICATE KEY UPDATE d=5,e=6,f=7;
You can read more about this handy technique here in the MySQL manual.
If you add a unique index on the ( A, B, C ) columns, then you can use REPLACE to do this in one statement:
REPLACE works exactly like INSERT,
except that if an old row in the table
has the same value as a new row for a
PRIMARY KEY or a UNIQUE index, the old
row is deleted before the new row is
inserted...