Steve Piercy - Web Site Builder Re: grid with join? [solved]
Mar 06, 2010; 23:03
Steve Piercy - Web Site Builder
Re: grid with join? [solved]
Attached are the files to get JOINs to work with Knop.
Following are code samples to use.
----------------------------------------- cfg ----------------------------------------- [ // create grid object for the record list var('list')=knop_grid( -database=$db_blocks, -nav=$nav, -quicksearch=$lang_ui->search, -numbered);
// add columns to the list $list -> addfield( -label='ID', -dbfield='id', -name='i', -width=10); $list -> addfield( -label='Block Name', -dbfield='blocks.name', // table.column must be actual field, no aliases -template={return(field('bname'))}, // the field may be a column alias -url='admin/blocks/edit', -name='n', -width=100, -quicksearch); $list -> addfield( -label='Page Title', -dbfield='title', -name='p', -width=60, -quicksearch); $list -> addfield( -label='Slot Name', -dbfield='slots.name', -template={return(field('sname'))}, -name='s', -width=60, -quicksearch); ]
----------------------------------------- lib ----------------------------------------- [ var('sql') = string; $sql = "/* Your SQL string */ select blocks.id, blocks.keyfield, /* Alias the column to remove ambiguity when two or more columns from different tables have the same name. The alias goes here in the cfg file here: ->addfield( ... -template={return(field('ALIAS_NAME'))} ... ) */ blocks.name as bname, pages.title, slots.name as sname from blocks, pages, slots where blocks.page_id = pages.id and blocks.slot_id = slots.id ";
// find out the current skiprecords value based on the -page parameter and $maxrecords $skiprecords = $list->page_skiprecords($maxrecords);
// build search params // first set some basic search parameters var('searchparams')=array( -maxrecords=$maxrecords, -skiprecords=$skiprecords, -uselimit);
// then add search parameters, if any if($list->quicksearch->size); $sql += " AND "; $sql += $list->quicksearch(-sql,-contains); /if;
// then add sort parameters, if any $sql += $list->sortparams(-sql);
// get list of records $db_blocks->select(-sql=$sql,$searchparams);
// check if the -page value was out of bounds if($list->page > $list->lastpage); // skiprecords too big, search again with corrected skip value // calculate last page $list->'page' = $list->lastpage; $skiprecords = $list->page_skiprecords($maxrecords); $searchparams->removeall(-skiprecords) & insert(-skiprecords=$skiprecords); $db_blocks->select(-sql=$sql,$searchparams); /if;
// clear any record locks if(action_param('deletebutton') != ''); $s_user->clearlocks; /if; ]
--steve
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Steve Piercy Web Site Builder Soquel, CA <web@StevePiercy.com> <http://www.StevePiercy.com/>
Attachment converted: MacBook:knop 5.lasso ( / ) (06A6A9A2) Attachment converted: MacBook:form.inc (TEXT/ ) (06A6A9A7) Attachment converted: MacBook:grid 4.inc (TEXT/ ) (06A6A9A8) -- ############################################################# This message is sent to you because you are subscribed to the mailing list <knop@lists.montania.se>. To unsubscribe, E-mail to: <knop-off@lists.montania.se> Send administrative queries to <knop-request@lists.montania.se> List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html Project homepage http://montania.se/projects/knop/ Google Code has the latest downloads at http://code.google.com/p/knop/
This message has the following attachments: file://localhost/Users/johan/Library/Mail/Attachments/BOOT.BIN
Search
Lasso Programming
This site manages and broadcasts several email lists pertaining to Lasso Programming and technologies related and used by Lasso developers. Sign up today!