We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20889
    • 19 Posts
    Hi,
    I get some data from a query in a snippet and then I want to create links with this data:

    if(mysql_num_rows($resultat) == 0) {
    echo "No hay ficheros en la base de datos
    ";
    }
    else {
    while(list($id, $name) = mysql_fetch_array($resultat))
    {
    ?>

    {{create_link_download}}

    <?php
    }
    }
    ?>

    the chunk should do teh next:

    <a href="download.php?id=<?=$id;?>"><?=$name;?></a>


    The problem is that i can’t read the value of $id and $name in the chunk.
    Does any body know how I could do it???
    Thanks in advance.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Set these values as placeholders in the snippet, then use the placeholder in the chunk.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 20889
        • 19 Posts
        Lots of thanks but what happens know is that it only stores the last value. My idea is to set a value to each round of the while and then call the chunk but It only receives the last value.

        else {
        while(list($idadjunts, $nom) = mysql_fetch_array($result))
        {
        echo "$idadjunts,$nom"; // to see the diferent values
        $modx->setPlaceholder(’id’,$idadjunts);
        $modx->setPlaceholder(’n’,$nom);

        ?>

        {{crear_link_download}}

        <?php
        }
        }

        ***********************
        {{crear_link_download}} code:

        <a href="test.com">[+n+],[+id+]</a>


        ***********************
        Output:

        1,plan_ritmo.jpg hosting.xls,9
        2,hosting.xls hosting.xls,9
        3,plan_ritmo.jpg hosting.xls,9
        4,hosting.xls hosting.xls,9
        5,plan_agenda.jpg hosting.xls,9
        6,plan_ritmo.jpg hosting.xls,9
        7,hosting.ods hosting.xls,9
        8,plan_agenda.jpg hosting.xls,9
        9,hosting.xls hosting.xls,9
          • 22303 MODX Staff
          • 10,725 Posts
            • 20889
            • 19 Posts
            Thats it. Lots of thanks !!!