CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Custom Code Help Echo [SOLVED]

Print topic Send  topic

Author Message
2advanced

Posts:
Posted: 01/04/2015, 12:03 PM

I have the following code in my common.php

// Get Users Country

$ip_address=$_SERVER['REMOTE_ADDR'];

/*Get user ip address details with geoplugin.net*/
$geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address;
$addrDetailsArr = unserialize(file_get_contents($geopluginURL));

/*Get City name by return array*/
$city = $addrDetailsArr['geoplugin_city'];

/*Get Country name by return array*/
$country = $addrDetailsArr['geoplugin_countryName'];

/*Comment out these line to see all the posible details*/
/*echo '<pre>';
print_r($addrDetailsArr);
die();*/

if(!$city){
$city='Not Define';
}if(!$country){
$country='Not Define';
}


// END Get Users Country

ok I want to be able to capture this in a text box but I for the default value of the text box I add

$country

but it does nothing how do I get it to display in a text box

View profile  Send private message
PCHome

Posts: 57
Posted: 01/04/2015, 1:20 PM

Your function is working fine but it is outputting an array containing the country and city so for me at my location it gives:

Array ( [country] => US [city] => San Jose )

You can return the values by:


$Values = getLocationInfoByIp();  
  
echo "Country " .$Values['country'] ."<br>";   
echo "City: " .$Values['city'];


I've always found it better to put custom functions into external included scripts as they are easier to work on without having to regenerate the Common.php each time.
View profile  Send private message
2advanced

Posts:
Posted: 01/04/2015, 1:43 PM

$values?
View profile  Send private message
2advanced

Posts:
Posted: 01/04/2015, 1:44 PM

Not sure I follow you here is the original code

I have a label called country and a textbox called country_code

I want the label to show country and I want the contry to populate in the textbox hidden field

Im not understanding your $values


echo '<strong>IP Address</strong>:- '.$ip_address.'<br/>';
echo '<strong>City</strong>:- '.$city.'<br/>';
echo '<strong>Country</strong>:- '.$country.'<br/>';

View profile  Send private message
PCHome

Posts: 57
Posted: 01/04/2015, 2:38 PM

Since your function is outputting an array, you have to get the values from the array before using them for anything. A Google search on "Get values from array" can clarify it better than I can here.

The output key=>name values from your function look like this:

Array ( [country] => US [city] => San Jose )

A function can return only one single value but it CAN return an array which itself can have multiple values as above. That is what you are doing so $country by itself is used only inside the function and is meaningless outside unless you specifically assign it to a value. To use it outside the function, you have to first assign it a value from the array. I used $Values but you can use anything you want:

$Values = getLocationInfoByIp();

Now the output is renamed to $Values and, since your function is using names as the key, you can easily call them with:

$Values['country']

which fetches the array value with the key name 'country"

. . . and, if you want to reassign them back to a variable, you can do:

$country = $Values['country'];

etc.

You don't really HAVE to create unneeded variables, though. You can do it like this (ip_address is not being outputted by the array so your function will need more work to include it):

echo "<strong>IP Address</strong>:- '.$Values['ip_address'].'<br/>';
echo '<strong>City</strong>:- '.$Values['city'].'<br/>';
echo '<strong>Country</strong>:- '.$Values['country'].'<br/>';

For CodeCharge Studio, you generally do not use echo as CCS has it's own function:

$GridName->LabelName->SetValue($Values['country'])

for putting text on the screen (see the CCS Help for how to use it). If you use echo, it will likely appear at the very top of the page outside all of the HTML. Echo is good for testing things in CCS but not for presenting it properly on the screen.
View profile  Send private message
2advanced

Posts:
Posted: 01/04/2015, 7:13 PM

Thanks for all your help PC but still trying to understand that we are on the same page

Where would I put this code

$Values = getLocationInfoByIp();

echo "Country " .$Values['country'] ."<br>";
echo "City: " .$Values['city'];

sorry still learning CCS


View profile  Send private message
PCHome

Posts: 57
Posted: 01/05/2015, 1:10 AM

There is no need to PM me if I don't answer instantly as I am not on the computer in the evenings until bedtime, especially as I already answered the question in my last posting. I'll try to be clearer below.

For the on-screen text, create an HTML Label where you want the text to appear, then add a Before Show event to the label. In the event, add.

$Values = getLocationInfoByIp();
$GridName->LabelName->SetValue($Values['country']);

$GridName is the name of your grid; LabelName is the name you gave the label. You can add a second label where you want the other text. If you want to use the same label for both values together, simply use:

$Values = getLocationInfoByIp();
$Location = "Country " .$Values['country'] ."<br>";
$Location .= "City: " .$Values['city'];
$GridName->LabelName->SetValue($Location);

This is presuming that the function is in Common.php or that it is in an external script being loaded there. The latter is preferred and be sure to regenerate the page or site after making any changes to Common.php. Any changes made to Common.php must be done within the CCS project and not done manually outside it.
View profile  Send private message
2advanced

Posts:
Posted: 01/05/2015, 9:48 AM

let me make it more clear I get the concept and I have it working to a degree my problem is that while

on my label before show I have

$Values = getLocationInfoByIp();
$gridname->Label1->SetValue($Values['country']);

it displays fine on my text box I have before show

$Values = getLocationInfoByIp();
$gridname->textbox->SetValue($Values['country']);

but the text box remains blank

View profile  Send private message
PCHome

Posts: 57
Posted: 01/05/2015, 9:54 AM

Well, of course you would also have to create a Before Show event for the text box. Otherwise it would not know to put anything there.
View profile  Send private message
2advanced

Posts:
Posted: 01/05/2015, 4:00 PM

I have before show

$Values = getLocationInfoByIp();
$gridname->textbox->SetValue($Values['country']);

but the box remains empty
View profile  Send private message
eratech


Posts: 513
Posted: 01/05/2015, 6:36 PM

Quote 2advanced:
I have before show

$Values = getLocationInfoByIp();
$gridname->textbox->SetValue($Values['country']);

but the box remains empty

Can I suggest you take a step back and get the textbook to show something first, to clarify if it's a problem with setting the textbox value itself, or something in the $Values setting:

  
//$Values = getLocationInfoByIp();   
//$gridname->textbox->SetValue($Values['country']);  
$gridname->textbox->SetValue("Disneyland");  

E
_________________
CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia
View profile  Send private message
ckroon

Posts: 869
Posted: 01/06/2015, 3:40 PM

Doesn't
$Values[`country`];
have to be something like
$Values[0];
?


_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
2advanced

Posts:
Posted: 01/06/2015, 11:58 PM

no I figure it out apparently it was a no go on the text field before show so I tried it on record before show and work perfectly thanks every one
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.