From: Roy J. <RJo...@sp...> - 2004-07-06 21:28:34
|
Hi JT, You understood me perfectly. I was unaware of the 'in' keyword for MySQL. = The trick for returning the template vars as the column names also = greatly simplifies the code I have presently. I can't thank you enough = for your patience and help with this. I'm just starting out with Perl and = the WebGUI API and obviously have a lot to learn. Thanks again, Roy >>> jt...@pl... 07/06/04 04:12PM >>> Pardon me if I misunderstood what you're trying to do. Your query only returns one row of data because you're where clause = includes the primary=20 key, which by definition will only give you one row of data. If you want = to get back all=20 the rows that match the primary keys in that array try something like: $sql =3D "select...from...where priKey in (".join(",",@PKlist).")"; Again, if I misunderstood, I'm sorry about that. If I haven't, the join = trick should=20 work nicely. Also, another neat trick (if you don't mind your template variables being = named your=20 field names) is that you can dump the paginator directly into your = template variables=20 like this: $var{data_loop} =3D $p->getPageData; # this creates your loop $p->appendTemplateVars(\%var); # this adds your paginator variables NOTE: Requires 6.0 or higher. On Tue, 06 Jul 2004 16:43:09 -0400 "Roy Johnson" <RJo...@sp...> wrote: >Greetings, > >I'm slowly learning the WebGUI API and am currently developing a macro = for our company=20 >and have a few questions. Before I ask my question, I'm basing most of = my code and=20 >assumptions on the SQLReports Wobject. > >Basically, I have an array with a single column of values that represent = primary key=20 >field values in a table. I'm executing the query once for each element = of the array=20 >and returning multiple columns from the query using the=20 >WebGUI::Paginator->SetDataByQuery() method. > >ex: > >foreach $primaryKey (@PrimaryKeyList) { > > $sql =3D "Select value1, value2, From tblBlah Where primaryKey=3D$primar= yKey"; > > $page =3D WebGUI::Paginator->new($url); > $err =3D $page->setDataByQuery($query, $dbh); > $rowData =3D $page->getPageData(); > > #Code to create hashes necessary for returning Template vars > >} > >The code that I have is working but I'm not sure that I'm approaching the = problem=20 >correctly. Because my query will never return more than one row during = a single=20 >itteration of the foreach loop (because the where clause is based on a = primary key=20 >field) it seems this is the wrong approach to take. =20 > >The problem is that I must execute the query once for each value in my = array so the=20 >cummulative result (what is sent to the macro in the form of template = vars) almost=20 >always has more than one row of information. So my template for the = macro looks=20 >something like this: > ><tmpl_loop rows_loop> ><tmpl_var row.field.value1.value><br/> ><tmpl_var row.field.value2.value> ></tmpl_loop> > >In case anyone is wondering why I didn't write my SQL statement better to = avoid the=20 >need for an array of the necessary primary key values, it's because we = are not running=20 >MySQL 4.1 and don't have the support for subselects and the 'having' = keyword. If we=20 >were, I could accomplish what I'm doing without the need for the array of = primary key=20 >values. > >Sorry for the long post. If anyone could nudge me in the right direction = for this type=20 >of programming challenge I would GREATLY appreciate it. > >Thanks, > >Roy Johnson > > > >------------------------------------------------------- >This SF.Net email sponsored by Black Hat Briefings & Training. >Attend Black Hat Briefings & Training, Las Vegas July 24-29 -=20 >digital self defense, top technical experts, no vendor pitches,=20 >unmatched networking opportunities. Visit www.blackhat.com=20 >_______________________________________________ >Pbwebgui-development mailing list >Pbw...@li...=20 >https://lists.sourceforge.net/lists/listinfo/pbwebgui-development=20 JT ~ Plain Black Create like a god, command like a king, work like a slave.=20 ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 -=20 digital self defense, top technical experts, no vendor pitches,=20 unmatched networking opportunities. Visit www.blackhat.com=20 _______________________________________________ Pbwebgui-development mailing list Pbw...@li...=20 https://lists.sourceforge.net/lists/listinfo/pbwebgui-development |