<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello David<br>
query works well with $sth->fetchall_arrayref
but the result with template toolkit doesn'work.<br>
<br>
<pre wrap="">return template 'result' => {
resultC => $sth->fetchall_arrayref,</pre>
}<br>
<br>
<br>
data are here on we page, I can see with DUMP<br>
<br>
[% USE Dumper %]<br>
[% Dumper.dump(resultC) %]<br>
<br>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
$VAR1 = [ [ '0003908', 'MME xxxx ANGELE', 'TOULON SUR ALLIER',
'7248' ], [ '00923', 'DR CHLIER VICOA', 'RUEIL MALMAISON', 'AC0605'
], <br>
...<br>
...<br>
...<br>
RRAOLIN', '121420171' ] ];<br>
<br>
<br>
I use <br>
<br>
<br>
[% FOREACH item IN resultC %]<br>
<tr><br>
<td>[% loop.count %] - <a href="[%
request.uri_base %]/detailClient/[% item.CodeClient %] "> [%
item.CodeClient %]</a> </td><br>
<td> <a href="[%
request.uri_base %]/detailClient/[% item.CodeClient %] "> [%
item.NomClient %] </a> </td><br>
<td>[% item.Ville %]</td><br>
<td>[% item.Adresse %]</td><br>
</tr><br>
[% END %]<br>
<br>
<br>
<br>
loop.count works, there all lines but other fields are empty<br>
<br>
my $sql =qq/SELECT Client.CodeClient ,
Client.NomClient,Client.Ville, ClientContrat.NumContrat FROM Client
INNER JOIN ClientContrat<br>
ON (Client.CodeClient =
ClientContrat.CodeClient)<br>
WHERE Client.CodeClient LIKE ?
LIMIT 10/;<br>
<br>
<br>
do you have a idea ?<br>
<br>
<br>
I try [% item.table.field %] without success<br>
<br>
bye<br>
Hugues.<br>
<br>
<div class="moz-cite-prefix">Le 28/01/2014 13:13, David Precious a
écrit :<br>
</div>
<blockquote cite="mid:20140128121348.6ccc5956@columbia" type="cite">
<pre wrap="">On Tue, 28 Jan 2014 09:34:02 +0100
Hugues <a class="moz-txt-link-rfc2396E" href="mailto:hugues@max4mail.com"><hugues@max4mail.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hello
I use dancer 1 with with mysql
@resultCC = database('db')->quick_select('ClientContrat',
{ NumContrat => { like => "$search%" } }, { limit => 10 } );
I send @resultCC to my template tt and it's work well
I would like to pass complex query
</pre>
</blockquote>
<pre wrap=""><snipped SQL>
</pre>
<blockquote type="cite">
<pre wrap="">I do not find solution to use current mysql connection , and
quick_select ? ( it 's ok only if I create new connection with ,
connect, prepare execute ....)
what is the best way to do that ?
</pre>
</blockquote>
<pre wrap="">
The database() keyword provided by Dancer::Plugin::Database gives you a
DBI connection handle (well, a subclass of one), so you can use it just
as you'd use DBI for more complex stuff, e.g.
my $sth = database('db')->prepare($sql);
$sth->execute;
template 'foo', { clients => $sth->fetchall_arrayref }
Also, in your example you had:
</pre>
<blockquote type="cite">
<pre wrap="">... WHERE Client.CodeClient LIKE '%" .$search. "%' LIMIT 10";
</pre>
</blockquote>
<pre wrap="">
Customary Bobby Tables warning - if you're going to interpolate a
variable directly, use e.g. database->quote($search) to make sure it's
quoted appropriately. Otherwise, what if $search contained e.g. "foo%';
TRUNCATE TABLE Client; --"? Don't leave yourself open to SQL
injection, it's a very common mistake.
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Salutations</pre>
</body>
</html>