When I initially tried to post this question, the screen hung up while trying to pay. Can you verify that I am not resubmitting this question for...

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your PHP question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your PHP question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

Customer

When I initially tried to post this question, the screen hung up while trying to pay. Can you verify that I am not resubmitting this question for me?

Now for the question, I need answered. I would like to get this asap.

Here is the link to my problem I have posted on StackOverflow.
http://stackoverflow.com/questions/18925273/how-do-i-retrieve-the-value-of-php-stdclass-object
Can you give me the code required to retrieve an attrvalue? I would like to specify the attrname.

Last updated
Reena Therese
Programmer

Thank you for choosing ExpertHelp LLC. My name is Reena and I am here to help you resolve your issues. Please wait while I prepare my answer for you. I might ask you to provide additional information if needed so I could provide you the steps that will resolve this issue. Appreciate your patience.

Please refresh your browser by every 3-5 minutes by pressing F5 on your keyboard or check your email, you will receive a notification every time I post a comment/answer.

Posted
Reena Therese
Programmer

Hi customer,

Have you tried using a forif with this? Also what information are you specifically trying to retrieve?

Posted
Customer

I have tried a few things. to no avail. What I would like to do is get the ID , which lies inside 'leadRecord'. This I am able to do. i use this code.

$leadId = $checkLead->result->leadRecordList->leadRecord->Id;

But when I try to retrieve a record's first name value, I am unable to get it. this is what I was using.

$firstname = $checkLead->leadAttributeList->attribute[0]->attrValue;

I have also been playing with this code, just to get it to spit out all values in the arrays.

$myArray = (array)$checkLead;

echo 'What have we here? '.var_export($myArray, true);

foreach($myArray as $row => $innerArray){
foreach($innerArray as $innerRow => $innerinnerArray){
foreach($innerinnerArray as $innerinnerRow => $value){
echo $value . "
";
}
}
}

as you see on the link I provided, I could recieve 1 or many records. I need to verify I have the right one. I will know based on user input their first and last name. So, I would like to iterate through the leadRecords and say 'if the input values match the array values,give me the ID of the lead and any other attribute values I ask for.' For example, their could be an attribute called 'phone number'. I would like to be able to retrieve that.

Does that explain it better?

Posted
Reena Therese
Programmer

You can try to modify the code provided below, see if that will somehow help.

Posted
Customer

I have tried this

$checkLead = $marketoclient->getLead('EMAIL', $marketoArray['Email']);
//print
r ($checkLead);

foreach ($checkLead->Results->LeadRecordList->LeadRecordList as $LeadRecord){

if($Attribute->attrName == 'FirstName')
{
echo 'The value is: ' . $attrName->attrValue;
}}

this is the error message I get

Warning: Invalid argument supplied for foreach()

It is occurring on the line "foreach....."

How do I fix that?

Posted
Reena Therese
Programmer

This is the basic code for the for if, it seems that it is having a problem passing the code into the array.

if (is_array($variable)) {  foreach ($variable as $item) {/do something}}

You can also press the {} button on the edit screen so that it will help you to format or change the code we are missing.

Posted
Customer

I don't want to sound completely helpless, but you are going to have to be a little bit more clear on that last suggestion. I kind of understand what you are saying...do I place your original suggestion in between the brackets that have /do something in them? And replace $variable with $checkLead?

Posted
Customer

do you have a status update?

Posted
Customer

I really need a solution tonight. Do I need to get a refund and see if somebody else can help?

Posted
Reena Therese
Programmer

Sorry for the late reply. Yes please try to replace the $variable with $checkLead.
I would like to give a reference code that I found as well that might help you with this. I also located it in stackoverflow.

Link

Posted
Reena Therese
Programmer

Hope this helps you in solving the issue. If the solution provided you information on how to fix/resolve/identify the problem, I request to show your appreciation for my efforts by clicking the Green ACCEPT ANSWER button right below my first response.

Posted
Customer

I have seen that link. tried to implement it, but it wasn't working. I tried your previous suggestion, and it didn't even echo the string.

Here is what I did

$checkLead = $marketoclient->getLead('EMAIL', $marketoArray['Email']);
//print
r ($checkLead);

if (is_array($checkLead))
{ foreach ($variable as $item) {
foreach ($checkLead->Results->LeadRecordList->LeadRecordList as $LeadRecord){

if($Attribute->attrName == 'FirstName')
{
echo 'The value is: ' . $attrName->attrValue;
}}

}}

I would like to clarify my expectations when I paid for your company's services. I am asking for specific code to accomplish my goal. I have done hours of research up to seeking this help. Can you give me specific code that I can plug in and test? I am not trying to sound rude, but I don't have the time to get "tips or suggestions". I am working on multiple things right now. I will be happy to try your code suggestions.

Can you deliver on this? I understand if it there was misunderstanding, and if you would rather decline the job and transfer me to somebody else.

Again, I don't want to sound rude, text can come off that way.

Posted
Reena Therese
Programmer

$checkLead = $marketoclient->getLead('EMAIL', $marketoArray['Email']);
//printr ($checkLead);
if (is_array($checkLead))
{ foreach ($Attribute as $attrName) {
foreach ($checkLead->Results->LeadRecordList->LeadRecordList as $LeadRecord){
if($Attribute->attrName == 'FirstName')
{
echo 'The value is: ' . $attrName->attrValue;
}}
}}

Posted
Customer

That doesn't give an error, but it doesn't work either. The echo doesn't even print out. I pasted an echo inside the if(is_array($checkLead)).

It didn't print that echo either. So, I did try something before that I thought might work.

$myArray = (array)$checkLead;

then I updated the code to reflect the new array name

here is the code.

$checkLead = $marketoclient->getLead('EMAIL', $marketoArray['Email']);
//printr ($checkLead);
$myArray = (array)$checkLead;
if (is
array($myArray))
{ echo "it is an array";
foreach ($Attribute as $attrName) {
foreach ($myArray->Results->LeadRecordList->LeadRecordList as $LeadRecord){
if($Attribute->attrName == 'FirstName')
{
echo 'The value is: ' . $attrName->attrValue;
}}
}}

It gave this error message.

Warning: Invalid argument supplied for foreach()

on this line

foreach ($Attribute as $attrName) {

Am I going down the right path? If so, how do I fix the error? Or do you have another idea?

Thanks,

JJ

Posted
Reena Therese
Programmer

What if you try to remove one of he foreach.

$checkLead = $marketoclient->getLead('EMAIL', $marketoArray['Email']);
//printr ($checkLead);
$myArray = (array)$checkLead;
if (isarray($myArray))
{ echo "it is an array";
foreach ($myArray->Results->LeadRecordList->LeadRecordList as $LeadRecord){
if($Attribute->attrName == 'FirstName')
{
echo 'The value is: ' . $attrName->attrValue;
}}
}

Posted
Reena Therese
Programmer

By the way if you would like to refund with us you can send an email to s**t@experthelp.com and it will be responded by our team within 12-24hrs.

We can also try this one out if ever:

$myArray = attrName::findbysql($sql); // returns an array
$attrName = $myArray[0]; // assign first element in array to attrName
$myArray = $attrName->attrValue;

Posted
Reena Therese
Programmer

By the way if you would like to refund with us you can send an email to s**t@experthelp.com and it will be responded by our team within 12-24hrs.

We can also try this one out if ever:

$myArray = attrName::findbysql($sql); // returns an array
$attrName = $myArray[0]; // assign first element in array to attrName
$myArray = $attrName->attrValue;

Posted
Reena Therese
Programmer

Hope this helps you in solving the issue. If the solution provided you information on how to fix/resolve/identify the problem, I request to show your appreciation for my efforts by clicking the Green ACCEPT ANSWER button right below my first response.

Posted
Andres Olvera
Programmer

Hello, my name is Andres. I will be taking over your question to try and get to a solution to your problem.

I read your question in StackOverflow and I already posted an answer. Here's the code I proposed there:

$lastname = '';

$leadRecord = $checkLead->result->leadRecordList->leadRecord;
if ( $checkLead->result->count > 1 ) {
    foreach ( $leadRecord as $leadRecordItem ) {
        foreach ( $leadRecordItem->leadAttributeList as $attributes ) {
            $found = false;
            $temp_lastname = '';
            foreach( $attributes as $attr ) {
                if( $attr->attrName == 'LastName' ) {
                    $temp_lastname = $attr->attrValue;
                }
                if ( $attr->attrName == 'FirstName' && $attr->attrValue == 'JJ' ) {
                    $found = true;
                }
            }
            if ( $found ) {
                $lastname = $temp_lastname;
                break;
            }
        }
    }
}
else {
    foreach ( $leadRecord->leadAttributeList as $attributes ) {
        $found = false;
        $temp_lastname = '';
        foreach( $attributes as $attr ) {
            if($attr->attrName == 'LastName') {
                $temp_lastname = $attr->attrValue;
            }
            if($attr->attrName == 'FirstName' && $attr->attrValue == 'JJ') {
                $found = true;
            }
        }
        if($found) {
            $lastname = $temp_lastname;
            break;
        }
    }
}

echo $lastname;

If you feel my answer has helped you get to a solution to your problem, please consider showing your appreciation by clicking the green Accept Answer button right below my response.

Last updated

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More PHP Questions...

Ask Your PHP Question & Get An Answer Now!