Saving incomplete strings into a DBF file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Saving incomplete strings into a DBF file

Post by raulbolanos »

Hi guys,

I got the next problem.

I send a filtered request to the database (MySQL) to get a remark, which the column is a utf8_general_ci collection type.

I use and echo to see what's the data that I get and this contains strange characteres. However they are correct in the database, but when I request for them I got this.

Resultado: ESTÁN CONSTRUYENDO UNA CAFETRIA EN LA ESCUELA. Resultado: TODAVÍA NO FUNCIONA LA CAFETERIA, POR LO QUE NO HAY VARIACIÓN.

Which should be, in fact it's saved like that into the DB:

Resultado: ESTÁN CONSTRUYENDO UNA CAFETRIA EN LA ESCUELA. Resultado: TODAVÍA NO FUNCIONA LA CAFETERIA, POR LO QUE NO HAY VARIACIÓN.

This is the function:

Code: Select all

function cObservacion($prim_key, $fieldname) {
  try {
    $conn = conectar();
    
    $query = "SELECT remark FROM mmic_data WHERE prim_key='" . $prim_key . "' AND fieldname='" .  $fieldname . "'"; 
	//echo 'Query answertext: ' . $query . '<br />';
    $result = mysql_query($query, $conn);
	
	if (mysql_num_rows($result) != 0) {
	  $observacion = utf8_encode(mysql_result($result, 0));
	  echo ' Resultado: ' . utf8_encode($observacion);
	  return $observacion;
	}
	/*
	  Regresar valor vacio, esto significa que esa pregunta no fue llenada en el cuestionario.
	  Esto es ocasionado por las preguntas filtro que excluyen algún periodo para la siguiente pregunta.
	*/
	else {
	  return '';
	}  
  }
  catch (Exception $e) {    
    echo '<br />Error: ',  $e->getMessage();
	mysql_close($conn);
  }
}
Therefore I get this returned scalar value and I saved it into a *.DBF file and the string is beign corrupted or because he weird characters.

I just add the utf8_encode function and it doesn't work anyway.

What du you think guys?
Last edited by raulbolanos on Fri Jun 04, 2010 1:20 pm, edited 1 time in total.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Saving incomplete strings into a DBF file

Post by Jonah Bron »

Well, either you need to add the <meta> tag to your HTML to specify UTF-8, or the database encoding is not UTF-8.
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Re: Saving incomplete strings into a DBF file

Post by raulbolanos »

Jonah Bron wrote:Well, either you need to add the <meta> tag to your HTML to specify UTF-8, or the database encoding is not UTF-8.
I just add this to the top of the web:

<html>
<head><meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"></head>
<body>

and it still doesn't work >_<

I belive, the problem is here

Code: Select all

  $observacion = utf8_encode(mysql_result($result, 0));
  echo ' Resultado: ' . $observaciond;
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Re: Saving incomplete strings into a DBF file

Post by raulbolanos »

I got it:

It was because I used twice the utf_encode statement.

Thank you!!
Post Reply