1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

[Solved] Display data from a loadAssocList

Discussion in 'Community' started by georgie, Sep 10, 2019.

Thread Status:
Not open for further replies.
  1. georgie

    georgie Member

    Level: Community
    Hello Fabrik community

    Sorry for these simple PHP question, but ... I block :oops:!

    I have never use it in Fabrik, I know my code begins to work because I can see good results in an array (with a var_dump or print).

    But I cannot display results beautifully in my website, arrrgh. I try some foreach syntaxes, without success.

    Please can you help me?

    Here my code:
    Code (Text):

    $monId = '{pipelines___id}';

    $myDb = FabrikWorker::getDbo(false, 5);

    $myQuery = $myDb->getQuery(true);

    $myQuery->select('link_contact, notes')
    ->from('pipelines_links')
    ->where('pipeline_id = ' . $myDb->quote($monId));

    $myDb->setQuery($myQuery);
    $myResults = $myDb->loadAssocList();

    Then?

     
    THX in advance for all advices!
    :rolleyes::rolleyes::rolleyes:
     
  2. startpoint

    startpoint Active Member

    Level: Community
    PHP:
    foreach($myResults as $k=>$v){
        echo '<pre>view contact: ' . var_export($v['link_contact'], true) . '</pre>';  
        echo '<pre>view notes: ' . var_export($v['notes'], true) . '</pre>';
    }
     
    georgie likes this.
  3. georgie

    georgie Member

    Level: Community
    Thank you.
    With your help and an old thread (http://fabrikar.com/forums/index.php?threads/solved-calc-element-to-return-multiple-results.41128/), I found the perfect solution I think, here:
    Code (Text):

    $monId = '{pipelines___id}';

    $myDb = FabrikWorker::getDbo(false, 5);

    $myQuery = $myDb->getQuery(true);
    // Requete de recuperation de la valeur concernee en fonction de l id d'origine
    $myQuery->select(array('link_contact, notes'))
    ->from('pipelines_links')
    ->where('pipeline_id = ' . $myDb->quote($monId));

    $myDb->setQuery($myQuery);
    $myResults = $myDb->loadObjectList();


    $list = array();
    foreach ($myResults as $row)
    {
        $list[] = "<p style='margin-bottom:0px'>" . $row->link_contact . " " . $row->notes . "</p>";
    }
    return  implode($list)  ;
     
    #Fabrik
     
    Last edited: Sep 11, 2019
  4. startpoint

    startpoint Active Member

    Level: Community
    It all depends on what you want to achieve and how much you can, of course.
    What I've written is just a guideline, not a decision.

    Please, close this thread, if you resolve the problem.
     
    georgie likes this.
Thread Status:
Not open for further replies.

Share This Page