1

I am probably over thinking this. I am building a module that should get values from the content table. Currently (I have tried many different variations) I am using:

<?php
class getIt
{
    //Query our content table using the built in JFactory class, and loadAssocList() function. 
    // this function returns an indexed array of objects from the table
    public function getMainQuery()
    {   
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select($db->quoteName(array('id', 'title', 'introtext', 'images', 'fulltext')));
        $query->from($db->quoteName('#__content'));
        $query->where($db->quoteName('state') . ' = '. $db->quote('1'));
        $query->order('ordering DESC');
        $db->setQuery($query);
        $res = $db->loadAssocList();

        foreach ($res as $row)
        {
            foreach ($row as $innerRow => $value)
            {
                print_r($innerArray,$value);
            }
        }
    }
}
?>

Ultimately I wan to get the results via:

$list = new getIt();
print_r($list->getMainQuery(2,4));

Where 2 and 4 == $arg1, $arg2. I can't figure how to properly assign variables to the array values in the loop.

closed as unclear what you're asking by mickmackusa, Zollie, Lodder Feb 4 at 12:35

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What is 2 and 4 in your example? – fruppel Jul 28 '15 at 8:15
  • I could post an answer based on wild assumptions of what I think you want, but I think I'll vote to close as Unclear and hope that you will improve this abandoned question. I don't know if you want to pass an array as one argument, or if you want to pass two atguments that are integers. I don't know how you want to use the variables in your method/query. – mickmackusa Feb 2 at 12:40
1

I may not be understanding you correctly, but you just want a specific value? Then use loadObject();

$db = JFactory::getDbo();
$query = $db->getQuery(true);

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('state');
$query->from($db->quoteName('#__content'));
$query->where($db->quoteName('id')." = ".$db->quote('1'));

$db->setQuery($query);
$result = $db->loadResult();
print_r($result);

In this I am selecting the state value where the id is === to 1.

  • Thank you, and my apologies, new to PHP. I wasn't sure what terms to use. What I want is to define arguments that I can just pass to the instantiated variable, that are dynamic to the array variables. Basically, I can build on the fly vars, for the array values, I am just lost on how to say "hey in this array, I want the value associated with Key->3->val->index. If that makes any more sense. – bbaldwin Jul 28 '15 at 3:51
  • echo $res->state; won't return anything as state it hasn't been defined in the select clause ;) – Lodder Jul 31 '15 at 9:23
  • Correct and updated. Not easy answering Q&A from your phone. – NicholasByDesign Jul 31 '15 at 10:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.