[Corrected FAQ] Retrieving item data e.g. for use in RSforms

More
12 years 6 months ago #24913 by arnaud.blain
I'm sorry but the code in FAQ doesn't work for me:

I tried to get in RS field Default value email field and also text field but it get nothing :

//<code>
$db = & JFactory::getDBO();
// Set a different item id if you don't want the current item ...
$fcitem_id= JRequest::getInt('id',0);
$fccat_id= JRequest::getInt('cid',0);
$view= JRequest::getVar('view');
if ($view!='items' && $view!='item' && $view!='article') {
return "not in items view";
}

$field_id=19; // CHANGE THIS TO THE ID OF YOUR FIELD
if ($fcitem_id) {
$query = 'SELECT c.title, c.alias, f.value '
.'FROM '.'#'.'__content AS c '
.' LEFT JOIN '.'#'.'__flexicontent_fields_item_relations AS f'
.' ON f.item_id = i.id AND f.field_id='.(int)$field_id
.'WHERE c.id = ' . $fcitem_id;

$db->setQuery($query);
$itemdata = $db->loadObject();
$item_title = $itemdata->title;
}
return $itemdata->value;
//</code>

best regards

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #24915 by ggppdk
Try changing
.' ON f.item_id = i.id AND f.field_id='.(int)$field_id
to
.' ON f.item_id = c.id AND f.field_id='.(int)$field_id


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #24933 by arnaud.blain

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #24936 by ggppdk
Ok put these lines at the top:
Code:
error_reporting(E_ALL); ini_set('display_errors', 1);

AND AFTER:
$itemdata = $db->loadObject();
Code:
if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()."<br>Query:<br>".$query); return null; }
to see if there is a DB query error,

also make sure the field id is correct


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #24956 by arnaud.blain
IT WORKS !!!

thank you so it was just a f...ing space that was needed before WHERE

I put the code in order you change it in the faq

//<code>
$db = & JFactory::getDBO();
// Set a different item id if you don't want the current item ...
$fcitem_id= JRequest::getInt('id',0);
$fccat_id= JRequest::getInt('cid',0);
$view= JRequest::getVar('view');
if ($view!='items' && $view!='item' && $view!='article') {
return "not in items view";
}

$field_id=19; // CHANGE THIS TO THE ID OF YOUR FIELD
if ($fcitem_id) {
$query = 'SELECT c.title, c.alias, f.value '
.'FROM '.'#'.'__content AS c '
.' LEFT JOIN '.'#'.'__flexicontent_fields_item_relations AS f'
.' ON f.item_id = c.id AND f.field_id='.(int)$field_id
.' WHERE c.id = ' . $fcitem_id;

$db->setQuery($query);
$itemdata = $db->loadObject();
$item_title = $itemdata->title;
}
return $itemdata->value;
//</code>

thanks

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #24994 by ggppdk
Fixed the FAQ article to have spaces so that DB query does not fail

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.818 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline