Page 1 of 1
JSON v PHP
Posted: Mon Jul 03, 2017 10:49 am
by Vegan
Code: Select all
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "ip2location";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT country_code FROM ip2location_db1 WHERE " + $useraddress + " BETWEEN ip_from AND ip_to";
$result = $conn->query($sql);
Given I have a database of locations, I was speculating if JSON or other mechanism could be used by JavaScript ad code blocks in WordPress to be able to use location more effectively.
Any ideas or suggestions?
Re: JSON v PHP
Posted: Mon Jul 03, 2017 9:07 pm
by requinix
To do what? What are you trying to accomplish? How does JSON matter for it?
And I assume that stuff you posted was just a demonstration of what you're doing and not your actual code, right?
Re: JSON v PHP
Posted: Wed Jul 05, 2017 6:51 pm
by Christopher
Vegan wrote:I was speculating if JSON or other mechanism
JSON is the standard way to deliver data to Javascript, but you can use XML, delimited data, etc., etc., etc.
Re: JSON v PHP
Posted: Thu Jul 06, 2017 3:16 pm
by Vegan
i am not sure what i need, my goal was to use PHP to grab a query the JavaScript to do more work
not sure how to move data back and forth in a header etc
in the theme i am using I can use PHP in the custom header area so I wondering if this area could be leveraged?
Re: JSON v PHP
Posted: Thu Jul 13, 2017 1:37 pm
by Vegan
Code: Select all
<script type="text/javascript">
var php_var = "<?php echo $php_var; ?>";
</script>
is about the best simple idea and for location with 2 characters, should be good enough
I was simply speculating at larger chunks of data from a database
Re: JSON v PHP
Posted: Thu Jul 13, 2017 6:32 pm
by Christopher
How about:
Code: Select all
<script type="text/javascript">
var php_var = <?php echo json_encode($php_var); ?>;
</script>
Re: JSON v PHP
Posted: Fri Jul 21, 2017 3:39 pm
by Vegan
will the json encode mangle a simple 2 lower case result from a SQL SELECT WHERE ....
Code: Select all
<script>
switch (php_var) .....
</script>
Re: JSON v PHP
Posted: Mon Jul 24, 2017 1:52 pm
by Christopher
Vegan wrote:will the json encode mangle a simple 2 lower case result from a SQL SELECT WHERE ....
I read the list of words you wrote, but I am not quite sure it means. Is it from a Trump-bot?

Re: JSON v PHP
Posted: Sun Jul 30, 2017 3:41 pm
by Vegan
Christopher wrote:Vegan wrote:will the json encode mangle a simple 2 lower case result from a SQL SELECT WHERE ....
I read the list of words you wrote, but I am not quite sure it means. Is it from a Trump-bot?

https://www.facebook.com/Dump-Trump-123751574666262
I have not had much time to work on coding, been busy try to keep food on the table.
The code I posted seems to work with a chunk of code in the header and then snagging as needed with some javascript for use later in some advert
Lately Amazon has moved towards globalized advertising, but they are so far behind the curve