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?
Related
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 ?
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
When I am searching my MySQL database with some query like:
SELECT * FROM mytable WHERE mytable.title LIKE '%副教授%';
("副教授" are three Chinese characters, whose decimal numeric character reference, NCR, is "副教授"), I got no result.
By looking into the phpMyadmin and browsing "mytable", the should-be-found entry is shown as "副教授". I think that is the reason for the failure of search.
Not all the entries in the same column are numeric character reference and some of them are just normal. Here is one pic of the table column shown in phpMySQLAdmin.
I wonder how I could search for all entries in my table in MySQL using one format regardless if there are shown in NCR or not. Or should I convert the NCR entries by running some script? Thanks.
your database table encoding should be utf-8 and when you insert new data you should run set names 'utf-8' query before insertion and this will contain all your data.
How to do checking before importing a CSV file in PHP?
I have a CSV file which contains the information with the columns id, name, telephone, email and have the database with the same columns. I have the PHP file which can import the CSV file into the database.
Now, I want to update the information by batch, how can I match the id, name between CSV file and database so as to avoid wrong data input (suppose the data in the database is correct but that in the CSV it is wrong).
At the end, the PHP can show the message that your CSV data is incorrect! Thanks! Anyone can help?
You can do this as follows:
Read your CSV using fread() and filesize()
explode() the data, probably using linebreak (\n)
Loop through each line of data with foreach
Explode each line, probably using comma (,)
Test each index of that array with preg_match() and a regex pattern to make sure it meets your requirements
Query your database with something like this (in PHP, untested)
$query = "UPDATE yourtable SET name='".$name."' WHERE id='".$id."'";
Make sure your query is santized using PDO or similar, to avoid SQL injection at all times.
That last bullet point is the key to your question, I think. You'll need to read about UPDATE and INSERT SQL queries - here's a question that may help: Mysql function: Insert if not exist or updated
You haven't included any code or a starting point in your original question, so I can't help you with the specifics, but I'm sure you can research this yourself. I'd say it's easy-intermediate difficulty.
I have been looking for this problem since a while so I guess I stuck.
Case is: I'm importing a large csv file into mysql database with Bigdump (thanks to A. Ozerov), delimiter is |, all is fine, this works.
In my last varchar field the values are usually: '', 'X', '1', '0'. Problem is if I do a select query to this field and look up values with '', I find none or one only. I checked a few lines one by one and found that the phpmyadmin shows a "textarea" instead of a textbox. I went and selected the field data and nothing was there (not even a carriage return). Still I could save the line and reopen it, when the textarea changed to textbox.
I wonder if anyone ever saw this error, and if there is a way to fix this database runtime from php (part of daily process), not line-by-line.
I even tried to copy paste both the csv and the database field to text editor to see if a char is there that I don't see.
The data I want to use is:
0 if the value is empty, 1 if the value is anything else. Currently I am not able to separate this two for the above reason.
Thank you in advance!
Check for hexcidecimal values in the column by doing this:
SELECT HEX(columnname)
Then use REPLACE to change the Hex values to Null or ''