I'm trying to get access to some information which are predefined in the backend of joomla
id asset_id title note active 90 61 Testtitle testnote 1
I've tried the same code with getInt ItemeId and it worked for another table but not for the suppose so i tried getInt id
This is some code im trying to get to work but the echo $note isnt working
<?php
defined('_JEXEC') or die;
$menuitemid = JRequest::getInt('id');
$db =& JFactory::getDBO();
$query = "SELECT note FROM #__modules WHERE published = 1 and id = '".$menuitemid."' ";
$db->setQuery($query);
$note = $db->loadResult();
?>
<div title="**<?php echo $note ?>**" class="custom<?php echo $moduleclass_sfx ?>" <?php if ($params->get('backgroundimage')) : ?> style="background-image:url(<?php echo $params->get('backgroundimage');?>)"<?php endif;?> >
<?php echo $module->content;?>
</div>
EDIT:
As with the suggestion provided ive edited my code to this (this also wont work actually):
defined('_JEXEC') or die;
$jinput = JFactory::getApplication()->input;
$menuitemid = $jinput->get('id', null, 'INT');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('note')
->from($db->quoteName('#__modules'))
->where($db->quoteName('published') . ' = '. (int)1 .
' AND' . $db->quoteName('id') . ' = '. $db->quote($menuitemid));
$db->setQuery($query);
$note = $db->loadResult();
?>
<div title="<?php echo $note ?>" class="custom<?php echo $moduleclass_sfx ?>" <?php if ($params->get('backgroundimage')) : ?> style="background-image:url(<?php echo $params->get('backgroundimage');?>)"<?php endif;?> >
<?php echo $module->content;?>
</div>
And finally with some own improvements i got this functioning code: To catch the specific module id ive changed the AND SELECTOION id to $module->id
defined('_JEXEC') or die;
$jinput = JFactory::getApplication()->input;
$menuitemid = $jinput->get('id', null, 'INT');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('note')
->from($db->quoteName('#__modules'))
->where($db->quoteName('published') . ' = '. (int)1 .
' AND' . $db->quoteName('id') . ' = '. $module->id);
$db->setQuery($query);
$note = $db->loadResult();
echo $note;
Ok lets go through this bit by bit. As mentioned in my comment, JRequest
is deprecated, so you will need to use the following:
$jinput = JFactory::getApplication()->input;
$menuitemid = $jinput->get('id', null, 'INT');
You're database query using using old coding standards and does not using any escaping methods. The following, which is also provided on the Joomla Documentation is what you should be using:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('note')
->from($db->quoteName('#__modules'))
->where($db->quoteName('published') . ' = '. (int)1 .
' AND' . $db->quoteName('id') . ' = '. $db->quote($menuitemid));
$db->setQuery($query);
$note = $db->loadResult();
echo $note;
In the query above, you will see I have use (int)1
which means that the value will always be an integer. I have also used quoteName()
for fields and quote()
for the value which are used to escape.
This will output the note
that you have assigned to the module. I have tested this and it works perfectly for me.
Hope this helps