Probably a no-brainer but google didn't help me the last 30 minutes so maybe someone has done this already and can nudge me to the right syntax;
I have a typical php-array like
$idArray = array(7) { [0]=> string(13) "55b753312986c" [1]=> string(13) "55b751f83d9f3" [2]=> string(13) "55b752b6ab7fd" [3]=> string(13) "55b7531fbb5ad" [4]=> string(13) "55b75346baae8" [5]=> string(13) "55b752c9aea0a" [6]=> string(13) "55b753417d577" }
I want to ask in the query if a property is in this array. I tried to put this into a parameter like
$queryParam = array("selectedID" => $idArray);
Next I wanted to query my DB like
MATCH (u:User) --> (n:Node)
WHERE u.id IN {selectedID}
RETURN u
Somehow the syntax is incorrect and I would appreciate a hint how to type the query accurately. Thanks very much.
Related
I am looping through GET values and only getting 13 values, not matter what URL I submit. Also, it is not getting the values in sequential order...
When I loop through I only get 13 values, as well as when I use a var_dump on $_GET itself; even though there are many more values to retrieve.
Here is the URL:
website.com/Questionaire.php?SurveyName=TV%20Quiz&SurveyType=MultipleChoice&Q1=Choose%20a%20character%20off%20of%20Happy%20Days?&A1=Benny%20the%20bull&A2=The%20Fonz&A3=Jack%20Cracker&Q3=Favorite%20Friends%20character?&A1=Ross&A2=Monica&A4=Joey&A5=Rachel&A6=Chandler&A7=Phoebe&Q8=Favorite%20Nickelodeon%20show?&A1=Hey%20Arnold!&A2=Rugrats&A8=Ahhhh!%20Real%20Montsters
Here are my results:
SurveyName: TV Quiz
SurveyType: MultipleChoice
Q1: Choose a character off of Happy Days?
A1: Hey Arnold!
A2: Rugrats
A3: Jack Cracker
Q3: Favorite Friends character?
A4: Joey
A5: Rachel
A6: Chandler
A7: Phoebe
Q8: Favorite Nickelodeon show?
A8: Ahhhh! Real Montsters
As you can see the results are not in sequential order and some values are even missing.
var_dump($_GET);
foreach ($_GET as $key => $value) {
echo $key.": ".$value."<br/>\n";
}
I expect these results:
SurveyName=TV Quiz
SurveyType=MultipleChoice
Q1=Choose a character off of Happy Days?
A1=Benny the bull //<- missed
A2=The Fonz //<- missed
A3=Jack Cracker
Q3=Favorite Friends character?
A1=Ross //<- missed
A2=Monica //<- missed
A4=Joey
A5=Rachel
A6=Chandler
A7=Phoebe
Q8=Favorite Nickelodeon show?
A1=Hey Arnold!
A2=Rugrats
A8=Ahhhh! Real Montsters
You cannot have identical parameter names in your query string, otherwise the last value will overwrite the previous ones. You need to have unique answer names or you will lose data. You can imagine PHP adding the parameters to $_GET with the following pseudo-code:
foreach($param as $key=>$val) {
$_GET[$key] = $val;
}
Because of this, parameters appear in the order in which they first show up in the request. So the query string ?A=1&B=2&A=3&C=4 will have A appear first, then B, and finally C. The last value for an identical parameter is the one used, so we get the following $_GET result:
array(
'A'=>3,
'B'=>2,
'C'=>4
);
Consider adding the question identifier as a prefix for each answer. For example, instead of A1 do Q1A1 and Q2A1. This will ensure that your data is not overwritten.
I would suggest using array notation for query string parameter names so that order is maintained. Something like:
?SurveyName=TV Quiz
&SurveyType=MultipleChoice
&Q[1]=Choose a character off of Happy Days?
&A[1][1]=Benny the bull
&A[1][2]=The Fonz
&A[1][3]=Jack Cracker
&Q[3]=Favorite Friends character?
&A[3][1]=Ross
&A[3][2]=Monica
&A[3][4]=Joey
&A[3][5]=Rachel
&A[3][6]=Chandler
&A[3][7]=Phoebe
&Q[8]=Favorite Nickelodeon show?
&A[8][1]=Hey Arnold!
&A[8][2]=Rugrats
&A[8][8]=Ahhhh! Real Montsters
When you name query string parameter like that, PHP will parse them into arrays:
array(4) {
["SurveyName"]=>
string(7) "TV Quiz"
["SurveyType"]=>
string(14) "MultipleChoice"
["Q"]=>
array(3) {
[1]=>
string(37) "Choose a character off of Happy Days?"
[3]=>
string(27) "Favorite Friends character?"
[8]=>
string(26) "Favorite Nickelodeon show?"
}
["A"]=>
array(3) {
[1]=>
array(3) {
[1]=>
string(14) "Benny the bull"
[2]=>
string(8) "The Fonz"
[3]=>
string(12) "Jack Cracker"
}
[3]=>
array(6) {
[1]=>
string(4) "Ross"
[2]=>
string(6) "Monica"
[4]=>
string(4) "Joey"
[5]=>
string(6) "Rachel"
[6]=>
string(8) "Chandler"
[7]=>
string(6) "Phoebe"
}
[8]=>
array(3) {
[1]=>
string(11) "Hey Arnold!"
[2]=>
string(7) "Rugrats"
[8]=>
string(21) "Ahhhh! Real Montsters"
}
}
}
I have really no idea what's happening. The story:
I use PDO for a SELECT statement on a database.
$sql = "SELECT a,b,c,performance,points,compare
FROM normvalues
WHERE x=:x AND y=1 AND z=:z";
$stmt = $GLOBALS['PDO']->prepare($sql);
$stmt->bindParam(":x",$x);
$stmt->bindParam(":z",$z);
$stmt->execute();
$res=$stmt->fetchAll(PDO::FETCH_ASSOC);
So that's fine and it is working. When I var_dump the $res variable I get something like:
array(6) {
["a"]=> string(2) "44"
["b"]=> string(4) "1176"
["c"]=> string(4) "1166"
["performance"]=> string(4) "50.1"
["points"]=> string(1) "1"
["compare"]=> string(2) "-1"
}
[1]=>
array(6) {
["a"]=> string(2) "57"
["b"]=> string(4) "1176"
["c"]=> string(4) "1166"
["performance"]=> string(4) "47.7"
["points"]=> string(1) "2"
["compare"]=> string(2) "-1"
}
[2]=>
array(6) {
["a"]=> string(2) "70"
["b"]=> string(4) "1176"
["c"]=> string(4) "1166"
["performance"]=> string(4) "44.7"
["points"]=> string(1) "3"
["compare"]=> string(2) "-1"
}
...
That's also okay. But I have to sort the result another way. So I am doing:
foreach($res as $e){
$this->normTable[$e['a']][$e['points']]=$e['performance'];
$this->normTable[$e['a']]['compare']=$e['compare'];
}
And now I am completely lost. By assigning $e['performance'] I get wrong values. Actually this should be the performance values.
[1176]=>
array(4) {
[1]=> string(2) "50"
["compare"]=> string(2) "-1"
[2]=> string(2) "48"
[3]=> string(2) "45"
}
I already checked the values in the database and they are correct. By doing doubleval() I'd get the right values, but the problem is that not every value is a double but also integer or string. I also tried to typecast with (string) but it's the same result. I have no explanation.
Update:
It's a very big project and I just tried to minimize it as possible and to make my problem as clear as possible. But now I have figured out something new:
I do an 'echo()' of my first variable in the normTable during the loop:
foreach($res as $e){
$this->normTable[$e['a']][$e['points']]=$e['performance'];
echo "a:".$e['a']." pt: ".$e['points']." perf: ".$e['performance']."-".$this->normTable[1176][1]."\n";
$this->normTable[$e['a']]['compare']=$e['compare'];
}
and the value is changing from '50.1' to '50'. Still can't figure out the reason. Is there a size limitaion of arrays in PHP?
UPDATE 2 and a big SORRY!
As I said, it is a big project. So the table I read out, has some values for some attributes twice or more. Actually such a case should not happen. That's why the answer is simple: It became 50 because 50 was assigned. I'm so sorry for having waisted your time. But I totally excluded this case and since I am also coding in C, my first thought was: memory leak - clear case!
Thanks for your help.
Meh, I don't have 50 reputation; can't comment only answer.
If you replace a with be in your loop, you should get your expected result (given your data sample). I.e.:
foreach($res as $e){
$this->normTable[$e['b']][$e['points']]=$e['performance'];
$this->normTable[$e['b']]['compare']=$e['compare'];
}
But I'm not sure this really solves your problem. YMMV.
This seems like it should be easy but I'm clearly just misunderstanding something. I'm making an API call to 5 Day Weather with the following code:
$file = file_get_contents("http://5DayWeather.org/api.php?city=Glasgow");
$weather = json_decode($file);
If i var_dump($weather) I get the following output:
object(stdClass)#1824 (2) {
["apiVersion"]=> string(3) "1.0"
["data"]=> object(stdClass)#1826 (7) {
["location"]=> string(12) "Glasgow, GBR"
["temperature"]=> string(2) "55"
["skytext"]=> string(13) "Partly Cloudy"
["humidity"]=> string(2) "88"
["wind"]=> string(1) "8"
["date"]=> string(10) "2014-10-03"
["day"]=> string(6) "Friday"
}
}
Right, that's all well and good, but how can I echo out single results? I feel like I've tried everything and just can't get anything to work, including (many for good measure):
$weather->temperature;
$weather['temperature'];
$weather{'temperature'};
I appreciate that it's my fundamental misunderstanding of how this array/object thing works but I've tried looking into it and can't figure out exactly what I should be doing with this feed.
Thanks a lot!
Try this:
echo $weather->data->temperature;
Very sorry to be asking one of these questions, but I have been trying for the past hour to figure this one out and I am just plain stuck.
I am trying to update a lot of columns at the same time. I am using PDO.
Some PHP code:
$db=db_connect();
$wid=$_POST['wid'];
$time=time();
$username=$_SESSION['s_username'];
$arr=explode("|", $_POST['idata']);
array_push($arr, $time,$username,$wid );
$statement = $db->prepare("UPDATE widgets SET file_id=?,delay=?,title=?,instructions=?,width=?,height=?,bg_color=?,bg_image=?,border-radius=?,offer_table_border_width=?,offer_table_border_color=?,offer_table_link_color=?,offer_table_link_hover_color=?,offer_table_bg1=?,offer_table_bg2=?,head_font_size=?,head_font_color=?,instructions_font_size=?,instructions_font_color=?,time=? WHERE username=? AND wid=?");
$statement->execute($arr);
var_dump($arr);
The code comes from an AJAX request in the format "var1|var2|var3..." etc. This information is split by the "|" delimiter and then a few variables are added, then the table should be updated.
Here is the result of the var_dump (this is what $arr equates to):
array(22) { [0]=> string(2) "40" [1]=> string(1) "0" [2]=> string(9) "My Title!" [3]=> string(16) "My Instructions!" [4]=> string(3) "700" [5]=> string(3) "500" [6]=> string(4) "#FFF" [7]=> string(27) "http://background-image.png" [8]=> string(1) "0" [9]=> string(1) "1" [10]=> string(7) "#81ABD6" [11]=> string(7) "#0588C6" [12]=> string(7) "#81ABD6" [13]=> string(4) "#FFF" [14]=> string(7) "#DDEEFF" [15]=> string(2) "24" [16]=> string(7) "#2779AA" [17]=> string(2) "18" [18]=> string(7) "#2779AA" [19]=> int(1349486490) [20]=> string(15) "myuser" [21]=> string(6) "2LvS4c" }
And once again, the PDO statement:
$statement = $db->prepare("UPDATE widgets SET file_id=?,delay=?,title=?,instructions=?,width=?,height=?,bg_color=?,bg_image=?,border-radius=?,offer_table_border_width=?,offer_table_border_color=?,offer_table_link_color=?,offer_table_link_hover_color=?,offer_table_bg1=?,offer_table_bg2=?,head_font_size=?,head_font_color=?,instructions_font_size=?,instructions_font_color=?,time=? WHERE username=? AND wid=?");
The result from this: There are NO ERRORS returned from errorInfo(). There IS a row where username="myuser" and wid="2LvS4c", but it is simply not updated. There must be some sort of syntax error that I can't see, and is not being returned with errorInfo().
I tried with a simpler query:
$statement = $db->prepare("UPDATE widgets SET file_id=? WHERE username=? AND wid=?");
$statement->execute(array($arr[0], $username, $wid));
And it works like a charm! So what is wrong with the big query? Thanks!
This page lists the allowable characters in identifiers for MySQL, and - (minus) doesn't appear to be one of them.
First, are you certain that border-radius is the correct column name? It uses a minus sign whereas all the others use the underscore, _. At a bare minimum, you should maintain some consistency in your naming.
Other than that, start removing one column at a time from the update statement until it works. If it's a problem with a specific column (or possibly command length, however unlikely), this sort of "change one thing and retry" strategy can pinpoint the problem.
I cannot seem to figure out how to send to a group in my list using mailChimp API
My code looks like this:
$conditions = array('field'=>'interests-1', 'op'=>'all', 'value'=>'myGroup');
$opts = array('match'=>'any', 'conditions'=>$conditions);
$retval = $api->campaignSegmentTest($listId, $opts);
But this yields bool(false). When fetched by
$retval = $api->listInterestGroupings($listId);
my list looks like this:
array(1) {
[0]=>
array(5) {
["id"]=>
int(1)
["name"]=>
string(10) "myList"
["form_field"]=>
string(5) "radio"
["display_order"]=>
string(1) "0"
["groups"]=>
array(5) {
[0]=>
array(4) {
["bit"]=>
string(1) "1"
["name"]=>
string(9) "myGroup"
["display_order"]=>
string(1) "1"
["subscribers"]=>
int(1)
}
[1]=>
array(4) {
["bit"]=>
string(1) "2"
["name"]=>
string(9) "myGroup_2"
["display_order"]=>
string(1) "2"
["subscribers"]=>
int(1)
}
}
}
}
I have looked in the API documentation and searched for the answer, but cannot seem to figure it out. Grateful for help!
Looks like you are using the PHP wrapper - the first thing to do, like the examples included with it do, is to check for any errors by looking at $api->errorCode before messing with the $retval.
When you do that I'm certain you will see an error telling you that you haven't passed a proper "conditions" parameter since it is an array of arrays, not an array.