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
Vegan
Forum Regular
Posts: 574 Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:
Post
by Vegan » Mon Jul 03, 2017 10:49 am
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?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Jul 03, 2017 9:07 pm
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?
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Jul 05, 2017 6:51 pm
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)
Vegan
Forum Regular
Posts: 574 Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:
Post
by Vegan » Thu Jul 06, 2017 3:16 pm
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™
My site is powered by LAMP
Vegan
Forum Regular
Posts: 574 Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:
Post
by Vegan » Thu Jul 13, 2017 1:37 pm
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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Thu Jul 13, 2017 6:32 pm
How about:
Code: Select all
<script type="text/javascript">
var php_var = <?php echo json_encode($php_var); ?>;
</script>
(#10850)
Vegan
Forum Regular
Posts: 574 Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:
Post
by Vegan » Fri Jul 21, 2017 3:39 pm
will the json encode mangle a simple 2 lower case result from a SQL SELECT WHERE ....
Code: Select all
<script>
switch (php_var) .....
</script>
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Mon Jul 24, 2017 1:52 pm
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?
(#10850)
Vegan
Forum Regular
Posts: 574 Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:
Post
by Vegan » Sun Jul 30, 2017 3:41 pm
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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP