Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column with accent character

I have a MySQL database where I have a table with several columns.

One is name like 'Hèllo', for example.

The problem occurs when I access the results of this column. Example:

$query = mysql_query (" SELECT * FROM ........... "); 
while($result = mysql_fetch_array($query)){
$myresult = $result["Hèllo"];
}
echo "$myresult";

This doesn't work because the name of the column contains the character 'è'. Are there any methods to solve this problem?

I tried:

 mysql_query("SET NAMES 'utf8'");
 <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
 <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
like image 527
Andrea php Avatar asked Dec 09 '25 09:12

Andrea php


1 Answers

By default mysql_fetch_array contains both "associative" and "number" indices, so if you know that this column on the third place just try to access it by index number:

$result[0],
$result[3],

etc.

HINT:

  1. It is better to use PDO

  2. Try to avoid such table/column names

like image 162
Subscriberius Avatar answered Dec 11 '25 23:12

Subscriberius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!