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.
Related
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.
I am trying to decode JSON
I am reading the JSON through STOMP. There are different JSON datasets so I need to work out which JSON dataset has come through. I do this by reading its title.
However there is one particular dataset I am having trouble reading
foreach (json_decode($msg->body,true) as $event) {
if(isset($event['schemaLocation'])) {
$schedule_id=($event['schedule']['schedule_start_date']);
$signalling_id=($event['schedule']['schedule_segment']['signalling_id']);
echo $schedule_id;
}
In the above example the isset function works fine and also $schedule_id obtains the right answer
However the $signalling_id gives an error of Undefined index:
Here is a dump of PART of the JSON (Its rather long............).The piece of JSON with the signalling_id is towards the end of the JSON. Any help to get the variable signalling_id much appreciated.
array(7) {
["schemaLocation"]=>
string(72) "http://xml.networkrail.co.uk/ns/2008/Train itm_vstp_cif_messaging_v1.xsd"
["classification"]=>
string(8) "industry"
["timestamp"]=>
string(13) "1410374918000"
["owner"]=>
string(12) "Network Rail"
["originMsgId"]=>
string(47) "2014-09-10T18:48:38-00:00vstp.networkrail.co.uk"
["Sender"]=>
array(3) {
["organisation"]=>
string(12) "Network Rail"
["application"]=>
string(4) "TOPS"
["component"]=>
string(4) "VSTP"
}
["schedule"]=>
array(11) {
["schedule_id"]=>
string(0) ""
["transaction_type"]=>
string(6) "Create"
["schedule_start_date"]=>
string(10) "2014-09-10"
["schedule_end_date"]=>
string(10) "2014-09-10"
["schedule_days_runs"]=>
string(7) "0010000"
["applicable_timetable"]=>
string(1) "N"
["CIF_bank_holiday_running"]=>
string(1) " "
["CIF_train_uid"]=>
string(6) "W64017"
["train_status"]=>
string(1) "1"
["CIF_stp_indicator"]=>
string(1) "O"
["schedule_segment"]=>
array(1) {
[0]=>
array(20) {
["signalling_id"]=>
string(4) "5Y75"
["uic_code"]=>
string(0) ""
["atoc_code"]=>
string(0) ""
["CIF_train_category"]=>
string(2) "EE"
["CIF_headcode"]=>
string(0) ""
["CIF_course_indicator"]=
............................................
schedule_segment is itself an array, so instead of
['schedule']['schedule_segment']['signalling_id']);
that should probably be
['schedule']['schedule_segment'][0]['signalling_id']);
As you can see in the var dump, signalling_id is inside another array. Use:
$signalling_id=($event ['schedule']['schedule_segment'][0]['signalling_id']);
If that one element array with key 0 is not constant throughout, you may need some logic to figure out what it is in each iteration.
Hello awesome programmers!
I am so sorry for the the novice question, however, I am having trouble finding a solution to my problem. I am attempting to run a for each loop through my array passed from my controller, however, the data being outputted is not the same as when I run a var_dump($array). I am thinking perhaps that I need to iterate through this object maybe? However, when I attempt to do so, I get a non-object error.
Controller:
$data['user_details'] = $this->ion_auth->user()->row();
View:
var_dump($user_details);
foreach($user_details as $item){
echo $item['email'];
}
The output of this is : "21nfn4111NR12" but should be roger#peterson.net!
I have also tried the object form:
var_dump($user_details);
foreach($user_details as $item){
echo $item->email;
}
However, it results in error trying to get property of non-object!
When I run the var dump I get the following:
object(stdClass)#21 (17) {
["id"]=>
string(1) "2"
["ip_address"]=>
string(14) "119.132.127.01"
["username"]=>
string(12) "roger petereson"
["password"]=>
string(40) "fdZxF/RQo4nZKmbA5XQlwefbc8f8e5c74899c3d0"
["salt"]=>
NULL
["email"]=>
string(19) "roger#peterson.net"
["activation_code"]=>
NULL
["forgotten_password_code"]=>
NULL
["forgotten_password_time"]=>
NULL
["remember_code"]=>
string(22) "44hjOlloLTIrkSrjSBVNie"
["created_on"]=>
string(10) "1404939094"
["last_login"]=>
string(10) "1405099607"
["active"]=>
string(1) "1"
["first_name"]=>
string(6) "Roger"
["last_name"]=>
string(5) "Peterson"
["is_owner"]=>
string(1) "1"
["user_id"]=>
string(1) "2"
}
The following line:
$this->ion_auth->user()->row();
returns an object not an array (check your var_dump output), so you just need to
echo $user_details->email;
I hope I can make this question clear enough.
I'm looking to put a list of arrays inside one master array, dynamically, so that it looks like this:
masterarray {
array1
{ [0]=>VAL1 [1]=>VAL2 }
array2
{ [0]=>VAL1 [1]=>VAL2 }
array3
{ [0]=>VAL1 [1]=>VAL2 }
}
I've tried, but I could only get it to look like this:
array(1) { [0]=> array(2) { [0]=> string(1) "1" [1]=> string(13) "CODE" } }
array(2) { [0]=> array(2) { [0]=> string(1) "1" [1]=> string(13) "CODE" } [1]=> array(2) { [0]=> string(1) "1" [1]=> string(13) "CODE" } }
array(3) { [0]=> array(2) { [0]=> string(1) "1" [1]=> string(13) "CODE" } [1]=> array(2) { [0]=> string(1) "1" [1]=> string(13) "CODE" } [2]=> array(2) { [0]=> string(1) "1" [1]=> string(13) "CODE" } }
And that's definitely not what I'm aiming for. Nothing seems contained. I need the format specified above.
I'm using the explode function on a string pulled from a file to make this table of arrays (I think you call it that)
Here is the code I'm using that's not working.
$variabledebugging = file("FILE.TXT");//LOOK IN THIS FILE FOR THE NUMBER AND SET IT TO A VAR.
$i=0;
foreach($variabledebugging as $placeholder){
$variabledebuggingtbl[] = explode("\t",$variabledebugging[$i]);
var_dump($variabledebuggingtbl);
$i++;
}
I've tried a couple of different variations, but that's the one I'm using now.
To be clear, that file being pulled (each line as a value in an array) has 2 things written to each line, separated by a tab character, so that's the system I'm going on.
Thank you! I'm sure this is a simple task, I just can't think it through.
Oh and while I'm at is there a way to make debugging more readable?
You ARE getting the right result. The reason it seems wrong is that you are running var_dump inside the loop. And why don't you use the $placeholder variable?
$variabledebugging = file("FILE.TXT");
foreach($variabledebugging as $placeholder){
$variabledebuggingtbl[] = explode("\t", $placeholder);
}
var_dump($variabledebuggingtbl);
I'm not sure what you mean by "making debugging more readable", but if you want some linebreaks and indentation you should just look in the generated HTML code. var_dump do add spacing to make it readable but it is ignored by the web browser. If you don't want to read the HTML source, just add your var_dump to a <pre> element.
This question already has answers here:
Make var_dump look pretty [duplicate]
(16 answers)
Closed 1 year ago.
I've seen some online pretty print modules for code. Anyone know of one that will format a multi-dimensional array into readable display?
Example, translate this:
array(83) { [0]=> array(2) {
["name"]=> string(11) "CE2 Options"
["type"]=> string(5) "title" } [1]=>
array(1) { ["type"]=> string(4) "open"
} [2]=> array(5) { ["name"]=>
string(8) "Template" ["desc"]=>
string(638) "test description"
["id"]=> string(9) "my_theme"
["type"]=> string(14) "selectTemplate"
["options"]=> array(13) {
Into this...
array(83) {
[0]=> array(2) { ["name"]=> string(11) "My Options" ["type"]=> string(5) "title" }
[1]=> array(1) { ["type"]=> string(4) "open" }
[2]=> array(5) {
["name"]=> string(8) "Template"
["desc"]=> string(638) "Test description"
["id"]=> string(9) "my_theme"
["type"]=> string(14) "selectTemplate"
["options"]=> array(13) {
[0]=> string(10) "test"
If you are dumping it to HTML document use the
<pre></pre>
it does exactly that.
If you want a nicer output than var_dump , then check out the alternatives listed here:
A more pretty/informative Var_dump alternative in PHP?
Particularily http://krumo.sourceforge.net/ provides a much more accessible DHTML view for variable dumps. (It requires an extra include() though.)
And if you actually want to keep the generated output as static html, you might have to write a smallish wrapper script.
the pretty version is just what you get when you have XDebug installed and html_errors is set to On. Then you use var_dump($array). And make sure you set children and depth to what you need. there you go