exporting php Data to excel starting with 0 - php

I want to export my php Data to excel.
But I am facing an issue
Values in a column start with something like '00003421' in php but when it is exported in excel, it shows only '3421' in the cell. It ignores the zero values. Moreover, I want them in text data type.
How can I export the data in plain text format as it is (including zeroes)?
I have tried starting with single quote like this '00032 but its showing in the excel as well with single quote
It's tabular data with 32 columns and around 20,000 rows.
Any way to resolve this ?

Related

unable to export a double data type number in .CSV

I have a number as 009103744779100000007284 when I try to export into .csv it is converting into exponent form.
EDIT
As per the comments below, I tried to open with Excel but when I format the cell number itself getting changed. Actual number should be '009103744779100000007284'
I found the steps to get required result.
1. Open excel workbook
2. Open the Import Wizard (Data -> From Text)
3. Select your .csv file and Import
4. In the dialogue box, choose 'Delimited', and click Next.
5. Choose your delimiters as comma and uncheck othermoptions. And then choose your Text qualifiers as {None} in the dropdown section,
click Next
6. In the Data preview field select the column you want to be text. It should highlight.
7. In the Column data format field, select 'Text'.
8. Then click finish.
To export double data type displayed with exponent (4.01924E+12), you must format the complete column to NUMBER before saving sheet into CSV file using Save As Excel functionality.
If this column contains some product codes, the non-significant zero are lost.
If non-significant zero are important and the size of the code is unknown, the only solution is to find an original file that contains full code STRING with all zeroes and to use solution proposed by Butterfly.

Swap Column of Data in phpMyAdmin

I have a database table with 6 columns of 365 rows of data. I need to swap the 3rd column (named 'Date_line') with new data while leaving the other 5 columns in place, without exporting the whole table, but can't get phpMyAdmin to work with me.
Normally I'd just truncate the table and upload a revised CSV file for the whole table, but here's the catch: I have to update 232 data tables with this same exact column of data (the column data is common to all 232 tables). To do all 232 individually would mean exporting each table, opening it in Excel, swapping the old column for the new one, converting to CSV then re-uploading. It would be a lot easier if I could just import a single column CSV to overwrite the old one. But I don't know how.
I'd like to do this using the phpMyAdmin interface... I'm not much experienced in assigning scripts. Is there a way?

php mysql encoding - fields full of question marks

I have some php scripts that read data from csv files and insert them to a mysql database. When I look at the table rows in phpmyadmin their data seems fine but when i open one of the rows for editing, the varchar fields become full of question marks. Also when I search the tables for any string the result is empty. the collation of the fields is utf8_general_ci....
Even a word like KAMZA displays like ��K�A�M�Z�A��
Whats the problem?

PHP mysql_query data size limit?

I am trying to UPDATE a mysql TEXT data-type column with a string contains near 6,000 characters inside (6 kb data-size). Then the column is not updated with that data.
Then when i test this column by updating with test data around 100 characters, it works.
So, is there any limit on mysql query processing?
If so, how can i adjust it?
I'm using XAMPP on MacOSX.
Try escaping your data properly. Your data would be truncated rather than denied (by default) by MySQL if it wouldn't fit. The max size for TEXT field is 64kb.
If your data contains characters like ' and " your query could fail. Add proper error handling to determine where and why things go wrong and escape your data accordingly.

how to import the excel data to the mysql database or using PHP?

the data base data is stored as the image shows. the table is products.
the data in excel is as the following shows.
but when i open it by notepad++. it shows like this:
1, the data's format which i prepared is right? if not? how to correct it?
supposed the csv filed named product.csv. when i using LOAD DATA INFILE .when should i put the csv file into? could i load it from my local computer to my site's server?
i want to update the price, if the price is null, then using 0 to fill. this is my command. but it doesn't work
LOAD DATA LOCAL INFILE 'D:\\product.csv' REPLACE INTO TABLE products
FIELDS TERMINATED BY ' '
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(products_model, #var1)
SET products_price = IF(#var1 = '', 0, #var1); -- Replace empty string with 0
i put the above command in phpmyadmin, it can run, but the data doesn't be updated. what's wrong with it?
ps: is there a way to use PHP to get this? if have, how to do it?
I haven't used the setup you're working with, but it looks like the code is trying to read a tab-delimited file. The file is comma-delimited.
So, maybe all you need to do is change:
FIELDS TERMINATED BY ' '
to
FIELDS TERMINATED BY ','
Probably this issue is solved already, but just to give some extra input (also for others who visit this page):
Did you check your excel sheet? It seems that you have your data (price) in a different column than your sql database.
In excel the price is located in sixth column, in your sql it is located in the THIRD column... you can see that in your notepad csv file. Each comma represent a column.

Categories