Support Forum

Every time that you post a problem, PLEASE add the Joomla and the extension's versions and revisions (for example: Joomla 3.3.6, Contact Enhanced 3.3.5), PHP version and Server's Operating System. If you only manage only one site it is easier if you edit your profile and just add that information to your signature. Don't forget to add a detailed description of the problem. If possible, write down all steps to simulate the problem.

Before submitting a new post, PLEASE make sure you are running the latest version, test in different browsers (IE, FF, Chrome,..) and clear Joomla and browser's cache after every change you make.

Also, most questions are already answered in our FAQ and in iFAQ and Contact Enhanced documentation pages.

PHP in an SQL - Multiple

13 years 2 months ago - 13 years 2 months ago #5261 by softforge
Thanks again for this great extension!

What I would like to achieve is effectively a dynamic MySQL statement, something like this:
SELECT id AS value, name AS text
FROM jos_some_table
WHERE id != < ?php echo JRequest::getInt(id); ? >
(without spaces in php tags)

This way, when using the content plugin, I can use the same form on different pages and it will produce a different select list on each page.

It feels like the above statement could be run through PHP eval before being run as a query. Would this possible?

Another option could be have a PHP custom field that allows any code to be run and returns an object of arrays that is handled in the same way as the SQL - Multiple custom field.

Any suggestions?

Many many thanks! :)

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

13 years 2 months ago #5263 by douglas
Dear SoftForge,

I avoid PHP eval() as much as I can because many users might have problems with it depending on the PHP.ini short_open_tags.

I'll study a way to accomplish this for the next version without parse errors.

Do you desperately need this feature or can you wait 2 or 3 weeks?

Right now I'm focused on upgrading my extensions to Joomla 1.6.

Best regards,

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

13 years 2 months ago #5264 by softforge
Thanks so much for the response and yes I can understand the problem as many will not know about the right hand opening php needing to be of the short notation form.

We could wait if we knew it could be done, that's the only issue, if it could then we can come back to that, if it cannot we may just need to see if we can do it another way. But I totally appreciate your need to focus on 1.6 and would hate to take you away from that, I know how quick you are from past experience.

If there was a rough proof of concept then that would be great, it would allow us to know which way we were going.

Thanks for the speedy response.

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

13 years 2 months ago #5267 by douglas
Dear SoftForge,

I can create this for you if you don't mind waiting. I know it is possible, it is just a matter of making it work for every possible configuration that is a bit tricky.

I'm a sabatarian, therefore I don't work on Saturdays (the Holy Sabbath), so if you reply to this thread I'll only be able to look at it again on either Sunday or Monday; I hope you understand;

Have a great weekend,

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

13 years 2 months ago #5268 by softforge
Totally understand, and have a good weekend

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

13 years 2 months ago #5299 by douglas
Dear SoftForge,

I've been having a hard time to create this feature the way I want.

The closest I got is using using the single quote in the value, so the SQL would look something like this:
SELECT value, text
FROM jos_contact_enhanced_cv
WHERE value = "'.JRequest::getVar('value').'"

Please open [Path to Joomla]/components/com_contact_enhanced/customFields.class.php
Add this code:
eval('$this->value'." = '".$this->value."';");
Right before this code:
if($this->params->get('isAdmin')){
	//echo '<pre>'; print_r($this); exit;
	$query	= 'SELECT m.from_id FROM #__contact_enhanced_messages m '
				.	' INNER JOIN #__contact_enhanced_message_fields mf ON mf.message_id = m.id'
				.	' WHERE mf.id='.$db->Quote($this->field_id);
	$db->setQuery($query);
	$user	= $db->loadResult();
	$user	= &JFactory::getUser($user);
}else{
	$user	= &JFactory::getUser();
}

I've tested and it is working. This will not be added in the final source code until I manage to come up with a better solution.

Best regards,

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

13 years 2 months ago #5305 by softforge
Hi Douglas,

Thanks very much for your advice. This is what we ended up doing:
$db->setQuery( eval($this->value) );
With this as the SQL:
return 'SELECT name AS value, name AS text FROM jos_zoo_item WHERE id = ' . JRequest::getInt(item_id);
This works perfectly and does exactly what we need so thanks!

I could imagine a new check box in the Custom Field Details for the SQL fields something like "Evaluate PHP" which an tip-box explaining how to return the correct data. Alternatively you could create a totally new PHP field type.

Anyway, thanks again for your help! :)

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

Powered by Kunena Forum

Copyright © 2018 IdealExtensions.com. All Rights Reserved.

This site is not affiliated with or endorsed by the Joomla!™ Project. It is not supported or warranted by the Joomla!™ Project or Open Source Matters™. The Joomla!™ logo is used under a limited license granted by Open Source Matters™, the trademark holder in the United States and other countries.
We may collect your IP address and your browser's User Agent string while using our site for security reasons and deriving aggregate information (analytics). This information is retained for a minimum of 1 and a maximum of 24 months.
Feedback