RE: [Templates] MySQL problem continued

[prev] [thread] [next] [Date index for 2005/01/20]

From: Simon Matthews
Subject: RE: [Templates] MySQL problem continued
Date: 10:39 on 20 Jan 2005
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C4FEDC.5200DE3B
Content-Type: text/plain

The problem is that you are not naming your DBI queries and the content of
the DBI object is getting mangled by you calling it again.

There are two solutions to this:

1. Create more than one DBI object like so....


[% USE q1 = DBI(.....) %]
[% USE q2 = DBI(.....) %]

Which is my preferred approach because some DBI connections do not allow you
to have more than one result set open at any one time.

More on this in:
http://www.template-toolkit.org/docs/plain/Modules/Template/Plugin/DBI.html
look for Using Named DBI connections.

2. As you are using mysql you can actually get away with having more than
one result set open so you can do something like this:

[% USE DBI(....) %]
[% results1 = DBI.query("the sql for your outer query") %]

[% FOREACH result = results %]
	[% FOREACH inner = DBI.query("your inner sql") %]

	[% END %]
[% END %]


You can find examples of this in t/dbi.t in the Template Toolkit
distribution

Hope this helps

S

 

------_=_NextPart_001_01C4FEDC.5200DE3B
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DUS-ASCII">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>RE: [Templates] MySQL problem continued</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>The problem is that you are not naming your DBI =
queries and the content of the DBI object is getting mangled by you =
calling it again.</FONT></P>

<P><FONT SIZE=3D2>There are two solutions to this:</FONT>
</P>

<P><FONT SIZE=3D2>1. Create more than one DBI object like so....</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>[% USE q1 =3D DBI(.....) %]</FONT>
<BR><FONT SIZE=3D2>[% USE q2 =3D DBI(.....) %]</FONT>
</P>

<P><FONT SIZE=3D2>Which is my preferred approach because some DBI =
connections do not allow you to have more than one result set open at =
any one time.</FONT></P>

<P><FONT SIZE=3D2>More on this in: <A =
HREF=3D"http://www.template-toolkit.org/docs/plain/Modules/Template/Plug=
in/DBI.html" =
TARGET=3D"_blank">http://www.template-toolkit.org/docs/plain/Modules/Tem=
plate/Plugin/DBI.html</A> look for Using Named DBI =
connections.</FONT></P>

<P><FONT SIZE=3D2>2. As you are using mysql you can actually get away =
with having more than one result set open so you can do something like =
this:</FONT></P>

<P><FONT SIZE=3D2>[% USE DBI(....) %]</FONT>
<BR><FONT SIZE=3D2>[% results1 =3D DBI.query(&quot;the sql for your =
outer query&quot;) %]</FONT>
</P>

<P><FONT SIZE=3D2>[% FOREACH result =3D results %]</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>[% =
FOREACH inner =3D DBI.query(&quot;your inner sql&quot;) %]</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>[% END =
%]</FONT>
<BR><FONT SIZE=3D2>[% END %]</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>You can find examples of this in t/dbi.t in the =
Template Toolkit distribution</FONT>
</P>

<P><FONT SIZE=3D2>Hope this helps</FONT>
</P>

<P><FONT SIZE=3D2>S</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C4FEDC.5200DE3B--

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] MySQL problem continued
Shanta McBain 19:33 on 19 Jan 2005

RE: [Templates] MySQL problem continued
Simon Matthews 10:39 on 20 Jan 2005

Re: [Templates] MySQL problem continued
Shanta McBain 17:26 on 21 Jan 2005

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52