You need to sign in to do that
Don't have an account?
chuckdubdub
Getting individual field value from a queryResult()
Here's my query that I am using with php4 nusoap:
$queryResult = $sfdc->query("select id, firstname, lastname, phone, description, fax from lead where id = '$id'");
print_r("\nquery by id: \n\n");
print_r($queryResult);
How do I just grab the value of "description" and assign it to a variable? I'm guessing I need to loop through $queryResult as an array somehow?
I tried setting a variable to $queryResult['description'] but to no avail!
Thanks!
Chuck
If you know that you are only going to get one record back you can just access the fields as $result->records->fieldname.
Code: Park
Great, thanks for these tips. So if I'm doing this:
if ($queryResult->size == 1) $recs = array($queryResult->records->description);
// else $recs = $queryResult ->records;
echo print_r($recs);
The value I'm getting for $recs is "1", but I want to get the actual value of "description". Am I doing this right?
Thanks for your patience as I noodle through this!
Code:
This is an example of working code to parse out a query result. It expands on Ryan Choi's example code.
The key is that objects can be referenced as object->element but arrays must use array['element']. Also, the result is somewhat structured.
It helps to use a PHP development tool such as Nusphere or Zend. Then you can step through your PHP code and see the variable values and structure as you go.
Awesome, this did it for me, thanks so much!
if ($queryResult['size'] == "1") {
$record = $queryResult['records'];
$values = $record->values;
$firstname = $values['FirstName'];
$lastname = $values['LastName'];
$phone = $values['Phone'];
$fax = $values['Fax'];
}
Find below a sample code which displays the ten most viewed articles in the 'phone' category as an HMTL list of links. Phone is in the 'products' category group.
<apex:outputPanel layout="block">
<ul>
<knowledge:articleList articleVar="article"
categories="products:phone"
sortBy="mostViewed"
pageSize="10"
>
<li><a href="{!URLFOR($Action.KnowledgeArticle.View,
article.id)}">{!article.title}</a></li>
</knowledge:articleList>
</ul>
</apex:outputPanel>