This topic is locked
[SOLVED]

 php snippet echoing Greek chars, produces question mark

3/20/2012 7:40:25 AM
PHPRunner General questions
jimbeam author

Hello,
I have this code:

...blah blah blah construct a query called $sqlStreetName
$rs2 = CustomQuery($sqlStreetName);
$data2 = db_fetch_array($rs2);
foreach ($data2 as &$value) {

$is_face .= $value["address"].GetCustomLabel("yes");

}


The problem is that when I echo the $is_face variable, I get a "diamond encrasted" question mark instead of the $value["address"] value, concatenated with the proper result of GetCustomLabel("yes"). So, the result is this:

. The $value["address"] is in Greek and comes from mysql while the other one is from the custom labels functionality. Any ideas?
jim

C
cgphp 3/20/2012

Set the "Output code page" option as UTF-8 in the Misc tab: http://xlinesoft.com/phprunner/docs/miscellaneous_settings.htm

jimbeam author 3/20/2012



Set the "Output code page" option as UTF-8 in the Misc tab: http://xlinesoft.com...us_settings.htm


I have this at UTF-8 since the beginning.

C
cgphp 3/20/2012

If you are fetch only one column of only one record you don't need the foreach loop. Anyway, try this code:

...blah blah blah construct a query called $sqlStreetName

$rs2 = CustomQuery($sqlStreetName);

$data2 = db_fetch_array($rs2);

$is_face = '';

foreach($data2 as $key => $value)

{

$is_face .= $value.GetCustomLabel("yes");

}
jimbeam author 3/20/2012

I am fetching one column ("address") from many records. Your solution prints "array & array" which means that $value is an array:

. This is why I am using the $value["address"]. It's the greek chars that are problematic. I added a small improvement to fill the $data2 array but the problem still exists:



$rs2 = CustomQuery($sqlStreetName);



$data2 = array();

while($row = db_fetch_array($rs2)){

$data2[] = $row;

}
$i = -1; //loop counter

foreach ($data2 as &$value) {

$i++;

$is_face .= $value["address"];

if($i<(sizeof($data2)-1)){ //add the '&' character

$is_face .= ' & ';

}

}
C
cgphp 3/20/2012

Wouldn't it easier to have something like:

$rs2 = CustomQuery($sqlStreetName);

$is_face = '';

while($data2 = db_fetch_array($rs2))

{

$is_face .= $data2["address"] . ' & ';

}
$is_face = substr($is_face,0,-1);
jimbeam author 3/20/2012

Cristian, thanks for taking the time to help.
When I wrote " I added a small improvement to fill the $data2 array but the problem still exists:" I was wrong. This improvement actually solvedthe bug in my code.
The bug had to do with me not dealing with the array of results properly. These lines were missing:

while($row = db_fetch_array($rs2)){

$data2[] = $row;

}


regards
ps. The loop implementation is a matter of taste, I agree with your version but it's irrelevant with my huge bug <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=65038&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />