title: getting results from sql join using perl
body: <p>this works</p>
  
  <pre><code>TABLE users
  
  userid  firstname   lastname
  1        JOHN          DEO
  2        JANE          DEO
  
  TABLE msg
  
  msg_id    msg_from     msg_to      received   
  1         userid(1)    userid(2)   null       
  </code></pre>
  
  
  
  <pre><code>$janedeo_id = 2;
  
  
  my $data = $DBH-&gt;prepare("SELECT SND.userid, SND.firstname, SND.lastname
  FROM msg as M
  JOIN users as SND 
    ON SND.userid = M.msg_from
  WHERE M.msg_to = ? 
    AND M.received IS NULL");
  $data-&gt;execute($janedeo_id);
  while (my $row = $data-&gt;fetchrow_hashref) {
      foreach $row ( @$data) {
          ($userid, $snd_firstname, $snd_lastname) = @$data;
  }
  }
  my $templ    = &lt;&lt;START_HTML;
  &lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1
  +" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  [% FOREACH name IN list %]
  &lt;p&gt;userid    [% name.0 %] &lt;/p&gt;
  &lt;p&gt;firstname [% name.1 %] &lt;/p&gt;
  &lt;p&gt;lastname  [% name.2 %] &lt;/p&gt;
  [% END %]
  &lt;/body&gt;
  &lt;/html&gt;
  
  START_HTML
  
  $template-&gt;process (\$templ, { list =&gt; \@$data })
          or die $template-&gt;error;
  </code></pre>
  
  <p>this doesn't work. when i try to add age city country and results it fails cant works </p>
  
  <pre><code>TABLE users
  
  userid   firstname    lastname
  1         JOHN         DEO
  2         JANE         DEO
  
  TABLE msg
  
  msg_id    msg_from     msg_to      received   age  city  country
  1         userid(1)    userid(2)   null       26   any   any
  </code></pre>
  
  
  
  <pre><code>$janedeo_id = 2;
  
  
  my $data = $DBH-&gt;prepare("SELECT SND.userid, SND.firstname, SND.lastname, SND.age, SND.city, SND.country
  FROM msg as M
  JOIN users as SND 
    ON SND.userid = M.msg_from
  WHERE M.msg_to = ? 
    AND M.received IS NULL");
  $data-&gt;execute($janedeo_id);
  while (my $row = $data-&gt;fetchrow_hashref) {
      foreach $row ( @$data) {
          ($userid, $snd_firstname, $snd_lastname, $snd.age, $snd.city, $snd.country) = @$data;
  }
  }
  my $templ    = &lt;&lt;START_HTML;
  &lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  [% FOREACH name IN list %]
  &lt;p&gt;userid    [% name.0 %] &lt;/p&gt;
  &lt;p&gt;firstname [% name.1 %] &lt;/p&gt;
  &lt;p&gt;lastname  [% name.2 %] &lt;/p&gt;
  &lt;p&gt;city      [% name.3 %] &lt;/p&gt;
  &lt;p&gt;age       [% name.4 %] &lt;/p&gt;
  &lt;p&gt;country   [% name.5 %] &lt;/p&gt;
  [% END %]
  &lt;/body&gt;
  &lt;/html&gt;
  
  START_HTML
  
  $template-&gt;process (\$templ, { list =&gt; \@$data })
          or die $template-&gt;error;
  </code></pre>
  
  <p>am failing to get results when i try to add city age country to table msg and getting them printed out. am just getting blank response. even the script just printing error. cant find anything in database. so am just confused i don't know the problem</p>