negitron commented: piss off james +0
cereal commented: +1 +13
Ah, cheers!
Ah - great to know. Thanks for this!
I'm having some real trouble running some basic queries that I should be able to run easily.
I have a table called settings. When I query SELECT * FROM settings
I get the output:
+----+-----------------+--------------------------------+
| ID | key | value |
+----+-----------------+--------------------------------+
| 1 | view | default |
| 2 | sitename | value! |
| 3 | siteurl | |
| 4 | captcha.enabled | 0 |
| 5 | upload_path | http://web/uploads |
+----+-----------------+--------------------------------+
However, when I then run the simply query SELECT key FROM settings WHERE ID > 0
I get an error!
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key from settings where ID > 0' at line 1
mysql>"
If I wrap key
in single quotes, to make: SELECT 'key' FROM settings WHERE ID > 0
I get:
+-----+
| key |
+-----+
| key |
| key |
| key |
| key |
| key |
+-----+
So for the life of me I cannot understand why mySQL won't recognise the column name! The same thing happens for every column name as well, not just key.
If anyone knows what's going on here please let me know.
I understood that the AJAX script returns a response, which I then insert into the function and display in the console. However, I'm new to JS as well.
But I must apologise, because I was so caught up in the AJAX that I forgot that in my script I called a data validation class, which was preventing the page from returning the $_POST data.
Now that I have altered this it works perfectly! It looks like it was never an AJAX issue, so sorry for misleading everyone!
Hi all, just a quick question. I believed that $('#value')
was a jQuery function equivalent to document.getElementById('value')
however, in the code below, only the second function gives the desired result.
Can someone explain why this is?
$('#value').value = "1";
document.getElementById("value").value = "1";
After looking at the code for many hours now, I can't understand why it's not working... Is the Ajax form plugin incompatible with my version of jQuery?
I was just hosting the site locally, but I'll keep it up here for a small time: http://form.overheard.co.nz I've only just added it to the DNS records, so it may not work immediately.
I edited out a lot of details in the code I outlined above, but there are really just more input fields. Click the registration button to see the form I'm talking about.
I'm quite unfamiliar with exactly how headers work. Will the settings guiding how PHP handles headers be in the php.ini file, or elsewhere?
Cheers!
Ah cross fade, clever. That solves it.
Cheers!
Hi all,
I'm having some serious issues with AJAX forms. I'm currently using jQuery 2.2.0 and the jQuery Form plugin.
I have a simple php file:
<?php
if(isset($_POST)):
print_r(json_encode($_POST));
endif;
?>
I have a simple html form:
<form method="post" id="regform"> <input id="login_name" name="login_name" type="text" > <input id="login_password" name="login_password" type="text" > <input id="submit" type="submit"> </form>
I am trying to use AJAX to execute the PHP script and return the response. Here is what I have so far:
$(document).ready(function(){
$('#regform').on('submit', function(e) {
function response(response)
{
alert("The server says: " + response);
}
e.preventDefault();
var data = $(this).serialize();
$.ajax
({
type : 'POST',
url : '/?page=authenticate/register',
dataType : 'json',
data : data,
success : response(),
});
});
});
As far as I understand, I should be getting an alert box with the response. However, all I get isThe server says: undefined
So obviously AJAX is failing to make the call, and I cannot figure out why. Below is the XHR output:
XHR finished loading: POST "http://stronglinks.org/?page=authenticate/register"
.l.cors.b.crossDomain.send @ jquery.min.js:
4n.extend.ajax @ jquery.min.js:
4(anonymous function) @ (index):
216n.event.dispatch @ jquery.min.js:
3r.handle @ jquery.min.js:3
Can anyone help?
Hi all, I have two square <div> containers one under the other. When I click a button, I would like the second <div> to fade on top. Because the top <div> is transparent, the bottom <div> needs to be hidden first.
I have given the second div a Z-index of 2 and the first div has a z-index of 1. Here is the problem, when I call the fadeIn function, the bottom <div> SNAPS to the front, then dissapears before fading in as you would expect.
So far I have:
$("#registration-form").hide();
$("#register").click(function() {
$("#registration-form").fadeIn();
});
Is there some way to make this work?
If I extend the foreach to the below:
foreach($response as $statuses)
{
foreach($statuses as $s)
{
foreach($s as $key => $a)
{
echo '<pre>';
var_dump($key);
echo '<pre>';
//Store all IDs in Array
$id_array[] = $a->id;
}
}
}
I get the same error, but var dump shows:
string 'metadata' (length=8)
string 'id' (length=2)
So I cannot understand why $s->id
isn't accessing the id property.
Hi all,
I have an array of objects that looks like this:
object(stdClass)[2]
public 'statuses' =>
array (size=97)
0 =>
object(stdClass)[3]
public 'metadata' =>
object(stdClass)[4]
public 'iso_language_code' => string 'en' (length=2)
public 'id' => int 700797209428668416
1 => ...
n => ...
I a simply trying to iterate through the array of objects and access the 'id' property. The code I am using is:
foreach($obj_array as $statuses)
{
foreach($statuses as $s)
{
//Store all IDs in Array
$id_array[] = $s->id;
}
}
However, I am getting the error: Undefined property: stdClass::$id
I'm very new to working with classes, so I suspect I've just fundementally mis-understood how the data is structured.
I thought the 'id' property may be a property of 'metadata' but even $id_array[] = $s->metadata->id;
gave me the same error.
Any help would be appreciated!
Thanks for the replies. I ended up doing something quite simple. Instead of:
$mergeField[] = ['MERGE'.$i.'' => $d];
I did:$mergeField[$field] = $d;
And that worked nicely. Might be a tad more inefficient that what was suggested here.
hi all,
I am trying to make an array that looks like this:
Array
(
[status] =>
[MERGE0] => removed@email.address
[merge_fields] => Array
(
[MERGE1] => James
[MERGE2] => doe
)
)
In my code, there is an undefined number of [merge_fields], so I am using the code below to try create an array in the above format:
$i = 0;
foreach($data as $d):
$mergeField[] = ['MERGE'.$i.'' => $d];
$i++;
endforeach;
$json2 = [
'status' => $status,
'MERGE0' => $data['email'],
'merge_fields' => $mergeField
];
However, this outputs this:
Array
(
[status] =>
[MERGE0] => removed@email.address
[merge_fields] => Array
(
[0] => Array
(
[MERGE0] => removed@email.address
)
[1] => Array
(
[MERGE1] => James
)
[2] => Array
(
[MERGE2] => doe
)
[3] => Array
(
[MERGE3] => Masterton
)
)
)
Basically, I need to get rid of the parent keys for each merge item... How do I go about this??
< 180
is the limit on the for loop. 180 - 1
is the value of $i on the last loop.
The purpose of setting time() is to have a different values, and when while ($currentTime < $time + 1800)
i.e., when the time right now is equal to or greater than the time we started the loop + 1800 seconds, the loop stops.
Anyway, I have found a solution that doesn't use a while loop. Instead I reset my $i value and use a variable $iteration to track how many times the for loop has executed. It works very well!
for($i = 0; $i < $loops; $i++)
{
//Code
if($i == $loops - 1): //IF $i is last in loop
$i = -1; //Will change to zero at end of this loop
$iteration++;
sleep($x_seconds)
elseif($iteration == 10): //10 = final iteration
break;
endif;
}
This loops through the values of $i, waits for $x_seconds, then continues for another iteration until equal to the iteration variable.
Hi all, I am trying to get a for loop to cycle through, sleep, and then keep going until a specified time. I'm running into memory errors and unsure whether this is legitimate, or because its created a memory leak. My code is:
$currentTime = time();
$time = time();
while ($currentTime < $time + 1800)
{
for($i = 0; $i < 180; $i++)
{
//code
if($i == 180 -1):
$i = 0;
sleep(600);
endif;
$currentTime = time();
}
}
My logic is that when the for loop gets to the end, it resets it self for the next set, and when it wakes up again it can start from the beginning. It will do this until the current time equal approaches the $time + 1800 value.... Is this the correct approach? It's a hard issue to diagnose since the error is simply a memory one.
Hi all,
I'm using nginx to host multiple servers on one terminal through virtual hosts. Each one needs to be able to send emails, but I am unsure how to specify which account to use when I call the php mail() function.
Should I be specifying in the nginx configs which one to use?
Thanks guys, some really great answers!
hi all,
I have been coding a payment gateway using a company called SwipeHQ. Using their APIs I have programatically created products from my website and make sure they stay updated. However, I'm now completely stuck about how to have my checkout navigate to their payment form and then return back.
The flow diagramme would look something like this:
My Website Checkout -> update product details on SwipeHQ -> redirect to SwipeHQ payment form -> (success) navigate back to cart -> update stock / tidy things up -> redirect to thank you page.
I have tried using something like header("Location: https://payment.swipehq.com/?identifier_id=" . $transactionId);
but this just gives me an error message.
Could someone let me know vaguley what the correct protocol is for doing something like this?
Ah, I discovered a new function!
$ph = call_user_func_array('array_merge', $ph);
Compacted everything nicely. Very slow though, so if someone has a better solution please let me know :)
Hi all,
I am aiming to create an array with the same structure as this:
Array
(
[798D25C0DEABD] => Array
(
[quantity] => 1
)
[40B2B0FA3D222] => Array
(
[quantity] => 1
)
)
The code I am using is therefore:
for($i = 0; $i < count($response); $i++)
{
$ph[] = array($response[$i] => array('quantity' => $iteminfo[$i][1]));
}
However, this outputs an array that looks like this:
Array
(
[0] => Array
(
[EB9A045DF3F11] => Array
(
[quantity] => 1
)
)
[1] => Array
(
[79EA2FC5287C0] => Array
(
[quantity] => 1
)
)
)
How do I get rid of the incremental sub-arrays and keep everything under the one? Using $ph =
on its own obviously doesn't work since it only stores the last array in the for statement. Can someone help?
Well, without really understanding what happened, I managed to resolve the issue I had. To make things simpler, I used json_decode(value, true) to turn all the objects into arrays, and then found it all easier to manipulate.
What I don't understand is when the object I get from $order->get_items looks like:
stdClass Object
(
[356] => stdClass Object
(
[name] => steel wool 3
[qty] => 1
[other values]....
)
)
Why I can't do something like $itemsinfo->356->name
like I do with $html->data->identifier.
Doing the former returns null. Though like I mentioned, I'm really after trying to figure out why $response things it's a string.
Hi jkson, thanks for getting back to me.
The first stdObject I get is from a wordpress plugin. $order->get_items
returns the first standard object array. The first foreach code I wrote is supposed to extract the values I get from that object.
$request is an object returned from an API call, originally in JSON, I use json_decode to return an object array: $response[] = $html->data->identifier;
Therefore, $response when print_r'd looks something like this:
Array
(
[0] => 15D49BF5826A9A
[1] => EB99EABF5B391
)
How can $request possible be a string when it looks like that?!
Hi all,
Been really trying to get a grips with objects in PHP. I think my lack of understanding isn't helping here! Basically, with the help of another user here I managed to filter some object values and add them a nice array. I used the following code:
$i = 0;
foreach ($itemsArray as $key => $obj2)
{
foreach($obj2 as $key2 => $value)
{
if($key2 == 'name' || $key2 == 'qty' || $key2 == 'line_total')
{
$iteminfo[$i][] = $value;
}
}
$i++;
}
However, later on in my code, I want to add a different object to an array. Here I use this code:
$response[] = $html->data->identifier;
I want to know how I would use that approach in the first example, because that notatation makes more sense. The original object format looked like:
stdClass Object
(
[356] => stdClass Object
(
[name] => steel wool 3
[qty] => 1
[other values]....
)
)
But there is a more pressing issue. I want to the values from $iteminfo and $response into one. To do that, I am using the following under a foreach:
$response[$i][] = $qty;
I figured that this would add the $qty value underneath the value from $responses. However, I get the error: '[] operator not supported for strings'.
When I get rid of the $i and just have $response[] it works fine. Really confused what is happening here, is the $qty value not a real value at this point or is it still …
Ah, nvm. Simple change to $iteminfo[$i] = $value;
fixed this.
Thanks!
Thanks, that seems to have helped. Just one more question though. I modifed the code a little to filter out the values I want:
foreach ($itemsArray as $key => $obj2)
{
foreach($obj2 as $key => $value)
{
if($key == 'name' || $key == 'qty' || $key == 'line_total')
{
$iteminfo[] = array($key => $value);
}
}
}
And that leaves me with:
Array
(
[0] => stdClass Object
(
[name] => steel wool 3
)
[1] => stdClass Object
(
[qty] => 1
)
[2] => stdClass Object
(
[line_total] => 666
)
)
What I really want to know now is whether it's possible to extract the values from the object. I tried using get_object_vars, and the error I get is that I passed an array when the argument called for an object. As an example, I tried this:
$iteminfo = get_object_vars($iteminfo[0]);
Which according to the output above should be the object...
Here is the result I get:
Array
(
[0] => stdClass Object
(
[374] =>
)
)
Yeah, it definitely is. I'm going to expand on this a bit more. I first start with an object when I go:
$itemsArray = $order->get_items();
This gives me something that looks like this:
stdClass Object
(
[356] => stdClass Object
(
[name] => steel wool 3
[qty] => 1
)
)
Now I've tried for the life of me to find a way to grab those values. I was using:
foreach ($itemsArray as $name => $item)
{
$iteminfo[] = array(
$name => $item->name,
$name => $item->qty
);
}
But this gives me an output of null, yet everything I've looked at online says this is the correct way to go about it. Any idea why this is happening? (the code I posted first was a little further down the line, but I thought I'd go back to the start and work my way down)
Hi all,
I have a fairly limited understanding of how objects work exactly, but basically I have:
$response[] = $html->data->identifier;
Which I would think stored the values as an array, but when I try to add something to that array with:$response[] = array('quantity' => $itemsinfo['qty']);
I get the error "[] operator cannot be applied to string". This confused me since the $itemsinfo['qty'] is an array element, so I think this is because the array was created from an object?
Hi all,
So I've never really understood the php mail function, but I've tried to set up msmtp after failing a bit with postfix. The problem I get now is when I go to send an email I get an error "unpexted TLS packed recieved". My account conf is:
account default
tls on
tls_starttls off
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on
host smtp.office365.com
port 587
user ***
password ***
logfile /var/log/mail/mail.log
I'm guessing that because this is a TLS issue, I'm not doing something that's causing office365 domain to reject me? Can someone help?
Hi all,
my understanding was that Nginx doesn't do any caching unless you tell it to. However, for some reason, all my filles are being cached, and so the website doesn't respond to change in css or js files etc.
I thought that the below server{} code would help:
location ~\.(?:css|js|json)$ {
access_log off;
expires modified +90d;
}
But it hasn't made any difference. I've tried setting expires to -1 and off with no effect.
Does anyone know why this is happening?
Thanks, nginx -t worked and told me what was going on!
How do I access those logs? Typing those commands into the console just gives me an unknown command error.
Hi all,
Brand new to nginx, but it seems to be the rising star, and suited to hosting high volumes like I'm doing. However, I'm having trouble setting up the config files. A day of google searching hasn't really helped.
My nginx.conf looks like:
events {
worker_connections 768;
# multi_accept on;
}
http {
# rewrite_log on;
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
# tcp_nopush on;
keepalive_timeout 3;
# tcp_nodelay on;
# gzip on;
#php max upload limit cannot be larger than this
client_max_body_size 13m;
index index.php index.html index.htm;
# Upstream to abstract backend connection(s) for PHP.
upstream php {
#this should match value of "listen" directive in php-fpm pool
server unix:/tmp/php-fpm.sock;
#server 127.0.0.1:9000;
}
}
include sites-enabled/*;
My sites-enabled looks like this:
server {
listen :80 default_server;
server_name ubuntutec.cloudapp.net;
root /var/www/html/;
index index.php;
# Additional rules go here.
include /etc/nginx/conf.d/*.conf;
}
And the included config file looks like:
# WordPress single site rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;
# …
Solved. Adding position: fixed;
to my CSS allows the video element to follow the constraints.
I understand that a stretched video will cause letterboxing or pillarboxing. But them problem I am having is setting the width/height of the video element. For example, the CSS:
.video {
width: 100px;
height: 200px;
}
does not cause letterboxing, instead the element only obeys the width constraint. My question is why doesn't the video element also obey the height constraint and display with letterboxing?
So does that mean if I want a video to fill a div, that obviously changes in aspect ratio depending on the screen its viewed on... then I can't do that??
Hi all,
I have a HTML video within a div that is 100% width of the page. I want the video fill the container and crop the height to fit. But so far I cannot get the video to expand at all!
I'm simply using:
.video {
width:100%;
}
and
<div class="main-content">
<video class="video" autoplay loop">
<source src="/wp-content/themes/StrongLinks/video.webm" type='video/webm'/>
<source src="/wp-content/themes/StrongLinks/video.mp4" type='video/mp4'/>
</video>
</div>
Can someone explain why the video object isn't obeying the 100% width command?
Ah - please ignore the 'blue' typo! That's not the reason this isn't working
Hi all,
I am tying to have a page header transparent with the background blurred behind it. So far, for some reason, the blur overlay is only blurring the logo in the header, but nothing else??
my HTML is:
<div class="overlay-blur">
<div class="page-header">
<img src="http://test.com/wp-content/uploads/2015/11/Strong-Links.jpg" class="logo"/>
</div>
</div>
And CSS:
div#page {
height: 1000px;
background-image: url('https://joyreceived.files.wordpress.com/2012/08/p_aurora_detail_full.jpg');
}
div.page-header {
margin: 0px;
background-color: rgba(255,255,255,0.5);
}
div.overlay-blur {
left:0;
right:0;
filter:blue(4px);
-o-filter:blue(4px);
-ms-filter:blue(4px);
-moz-filter:blue(4px);
-webkit-filter:blur(4px);
}
nav.navbar-default {
background-color: rgba(255,255,255,0.5);
}
/*Page Logo*/
img.logo {
margin-top: 10px;
margin-left: 20px;
height: 100px;
}
I think perhaps the nature of the blur is that it only blurs certain object - and maybe does't recognise the background image I have on the page?
Found an easy way to do it.
You were right about their being tonnes of loading animations online, I got a cool CSS one. Then I build my first div container with an overlay to blur out the page.
When I click the button that executes the script, I use the JS function:
function showDiv() {
document.getElementById('loading').style.display = "block";
document.getElementById('animation').style.display = "block";
document.getElementById('text').style.display = "block";
}
To reveal the containers :)
Thanks for your suggestions!
Chris_33. the script has no content on it, it just bounces back to the index. But from the front end, it looks as if it stays on the index page. I like the idea of using an animation on the body, but I don't think that would work in this case since the user never actually views that page.
Taywin, I don't submit a form, but basically what you are saying is just before the code to execute the script I load an animation, which will then go away once the script returns and the pae reloads?
Found out you can specify a format when creating the object :)
DateTime::createFromFormat('d/m/Y', $date);
It's not started via Ajax, but is that something I should look into?
Always get really confused when dealing with timezones...
I have a string 8/11/2013
, which I apply the following code:
$firstDate = new DateTime($rawData[$backdate][0]);
$firstDate = $firstDate->format('d/m/Y');
The issue is that PHP seems to think that the '11' is the day, when it's actually the month (I'm in NZ). When I print_r the DateTime Object, it recognises that the object is in NZ timezone... is this what is causing the problem, since the original string is in US date format??
Hi all,
I'm very very new when it comes to JavaScript, but I understand it's what I need to solve my problem.
Basically, I have a PHP script that takes a while to process (several minutes). This script is linked from my homepage and when the script finishes it redirects back to the homepage. I want to know if it's possible to have a simple loading animation on my homepage whilst the script executes, just something to show people that the script is still actually doing something.
Can anyone make any suggestions?
Yeah, that's what I was doing. I've just figured it out (another silly mistake). I set the line length to 50, when some lines were larger than that. Caused all the issues!
Furthermore, using array_filter($data);
does nothing - the blank value is still there!
Given that array_filter is supposed to get rid of null, '', or false values - surely something more sinister is happening?
Hi all, quite a strange problem here. I have a csv file with rows:
20/12/2011 4.75 4.75 4.53 4.55 94.74 432.98 4.57
21/12/2011 4.38 4.38 4.38 4.38 20.9 91.54 4.38
22/12/2011 4.19 4.19 4.17 4.17 8.54 35.71 4.18
23/12/2011 3.86 4.35 3.84 4.22 149.49 625.81 4.19
24/12/2011 4.33 4.33 4.33 4.33 27.22 117.88 4.33
I am pulling those into an array with the code:
$row = 1;
if (($handle = fopen($inputFile, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 50)) !== FALSE) //While not end of file
{
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++)
{
$data[$c] = (str_getcsv($data[$c], ' '));
$finalData[] = $data[$c];
}
}
fclose($handle);
return $finalData;
}
This is producing a very strange result. The array it returns looks like this:
[0] => Array
(
[0] => 20/12/2011
[1] => 4.75
[2] => 4.75
[3] => 4.53
[4] => 4.55
[5] => 94.74
[6] => 432.98
[7] => 4.57
)
[1] => Array
(
[0] => 21/12/2011
[1] => 4.38
[2] => 4.38
[3] => 4.38
[4] => 4.38
[5] => 20.9
[6] => 91.54
[7] => 4.38
)
[2] => Array
(
[0] => 22/12/2011
[1] => 4.19
[2] => 4.19
[3] => 4.17
[4] => 4.17
[5] => 8.54
[6] => 35.71
[7] => 4.18
)
[3] => Array
(
[0] => 23/12/2011
[1] => 3.86
[2] => 4.35
[3] => 3.84
[4] => 4.22
[5] => 149.49
[6] => 625.81
[7] => 4.19
)
[4] => Array
(
[0] =>
)
[5] => Array
(
[0] => 24/12/2011
[1] => 4.33
[2] => 4.33
[3] => 4.33
[4] => 4.33
[5] => 27.22
[6] => 117.88
[7] => 4.33
)
As you can see, one array is empty, but there is nothing in the CSV file to suggest why. The strange this is that it carries on to the next date in the timeseries as if everything is fine...
Can someone shed some light on this??