Forum OpenACS Development: accessing db_multirow variable in tcl

I want to be able to iterate through the results of a call like:

db_multirow core_units core_units_sql { }

I want to put all the values from "core_units" into a string that will look like this "start -> unit1 -> unit2 ->... -> unitn -> end;" I tried the following code:

set data "digraph elec { start"
while "x < $core_units:rowcount"
    set data "$data  -> $core_units:uos_code"
    set x [expr $x + 1]
set data "$data end; }"

however I seem to get an error saying :

can't read "core_units": no such variable
    while executing
"while "x < $core_units:rowcount"

Posted by Rocael Hernández Rizzardini on
read the docs here:

you can iterate with each row returned by the query:
db_multirow -extend { user_url } users users_query {
    select user_id first_names, last_name, email from cc_users
} {
    set user_url [acs_community_member_url -user_id $user_id]

Posted by russ m on

You can also iterate over a multirow after it has been created - check the documentation for template::multirow

For example,

db_multirow assets assets {
  select asset_id,
    from ...


set asset_id_l [list]
multirow foreach assets {
  lappend asset_id_l $asset_id

Technically it's equivalent to using a code block on the end of your db_multirow.