PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Sep 25, 2017 8:49 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: JSON v PHP
PostPosted: Mon Jul 03, 2017 10:49 am 
Offline
Forum Contributor

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 479
Location: Victoria, BC
Syntax: [ Download ] [ Hide ]
$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?

_________________
Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate 16 lbs grain to make only 1 lb meat, water for 6 months of showers and 34.1 lbs carbon dioxide
My sites are made with WordPress, which is a content management system, Joomla and Drupal are some alternatives


Top
 Profile  
 
 Post subject: Re: JSON v PHP
PostPosted: Mon Jul 03, 2017 9:07 pm 
Online
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6556
Location: WA, USA
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?


Top
 Profile  
 
 Post subject: Re: JSON v PHP
PostPosted: Wed Jul 05, 2017 6:51 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13431
Location: New York, NY, US
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.

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: JSON v PHP
PostPosted: Thu Jul 06, 2017 3:16 pm 
Offline
Forum Contributor

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 479
Location: Victoria, BC
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?

_________________
Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate 16 lbs grain to make only 1 lb meat, water for 6 months of showers and 34.1 lbs carbon dioxide
My sites are made with WordPress, which is a content management system, Joomla and Drupal are some alternatives


Top
 Profile  
 
 Post subject: Re: JSON v PHP
PostPosted: Thu Jul 13, 2017 1:37 pm 
Offline
Forum Contributor

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 479
Location: Victoria, BC
Code:
<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

_________________
Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate 16 lbs grain to make only 1 lb meat, water for 6 months of showers and 34.1 lbs carbon dioxide
My sites are made with WordPress, which is a content management system, Joomla and Drupal are some alternatives


Top
 Profile  
 
 Post subject: Re: JSON v PHP
PostPosted: Thu Jul 13, 2017 6:32 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13431
Location: New York, NY, US
How about:
Code:
<script type="text/javascript">
   var php_var = <?php echo json_encode($php_var); ?>;
</script>

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: JSON v PHP
PostPosted: Fri Jul 21, 2017 3:39 pm 
Offline
Forum Contributor

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 479
Location: Victoria, BC
will the json encode mangle a simple 2 lower case result from a SQL SELECT WHERE ....

Code:
<script>
switch (php_var) .....
</script>

_________________
Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate 16 lbs grain to make only 1 lb meat, water for 6 months of showers and 34.1 lbs carbon dioxide
My sites are made with WordPress, which is a content management system, Joomla and Drupal are some alternatives


Top
 Profile  
 
 Post subject: Re: JSON v PHP
PostPosted: Mon Jul 24, 2017 1:52 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13431
Location: New York, NY, US
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? :roll:

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: JSON v PHP
PostPosted: Sun Jul 30, 2017 3:41 pm 
Offline
Forum Contributor

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 479
Location: Victoria, BC
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? :roll:


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

_________________
Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate 16 lbs grain to make only 1 lb meat, water for 6 months of showers and 34.1 lbs carbon dioxide
My sites are made with WordPress, which is a content management system, Joomla and Drupal are some alternatives


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], requinix and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group