bigup401 has asked for the wisdom of the Perl Monks concerning the following question:
this works
TABLE users userid FNAME LNAME 1 JOHN DEO 2 JANE DEO TABLE MSG msg_id msg_from msg_to received 1 userid(1) userid(2) null $janedeo_id = 2; $janedeo_id = 2; my $data = $DBH->prepare("SELECT SND.userid, SND.firstname, SND.lastna +me FROM msg as M JOIN users as SND ON SND.userid = M.msg_from WHERE M.msg_to = ? AND M.received iS NULL"); $data->execute($janedeo_id); $datainfo = $data->fetchall_arrayref(); while (my $row = $data->fetchrow_hashref) { foreach $row ( @$data) { ($userid, $snd_FNAME, $snd_LNAME) = @$data; } } my $templ = <<START_HTML; <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +/> <title>Untitled Document</title> </head> <body> [% FOREACH name IN list %] <p>userid [% name.0 %] </p> <p>firstname [% name.1 %] </p> <p>lastname [% name.2 %] </p> [% END %] </body> </html> START_HTML $template->process (\$templ, { list => \@$data }) or die $template->error;
now my problem is here. i added title, age and country to table MSG. so i want to output them also
TABLE users userid FNAME LNAME 1 JOHN DEO 2 JANE DEO TABLE MSG msg_id msg_from msg_to received title age country 1 userid(1) userid(2) null mr 26 anywhere $janedeo_id = 2; $janedeo_id = 2; my $data = $DBH->prepare("SELECT SND.userid, SND.firstname, SND.lastna +me FROM msg as M JOIN users as SND ON SND.userid = M.msg_from WHERE M.msg_to = ? AND M.received iS NULL IN (SELECT title, age, country FROM MSG)"); $data->execute($janedeo_id); $datainfo = $data->fetchall_arrayref(); while (my $row = $data->fetchrow_hashref) { foreach $row ( @$data) { ($userid, $snd_FNAME, $snd_LNAME, $tile, $age, $country) = @$d +ata; } } my $templ = <<START_HTML; <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +/> <title>Untitled Document</title> </head> <body> [% FOREACH name IN list %] <p>userid [% name.0 %] </p> <p>firstname [% name.1 %] </p> <p>lastname [% name.2 %] </p> <p>title [% name.3 %] </p> <p>age [% name.4 %] </p> <p>country [% name.5 %] </p> [% END %] </body> </html> START_HTML $template->process (\$templ, { list => \@$data }) or die $template->error;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sql join with multiple select
by poj (Abbot) on Oct 03, 2018 at 17:37 UTC | |
by LanX (Saint) on Oct 03, 2018 at 21:18 UTC | |
by bigup401 (Pilgrim) on Oct 04, 2018 at 07:59 UTC | |
by poj (Abbot) on Oct 04, 2018 at 12:18 UTC | |
by bigup401 (Pilgrim) on Oct 04, 2018 at 14:01 UTC | |
by poj (Abbot) on Oct 04, 2018 at 14:28 UTC | |
| |
by marto (Cardinal) on Oct 04, 2018 at 14:32 UTC | |
| |
|
Re: sql join with multiple select
by AnomalousMonk (Archbishop) on Oct 03, 2018 at 18:51 UTC | |
by bigup401 (Pilgrim) on Oct 04, 2018 at 08:03 UTC | |
|
Re: sql join with multiple select
by LanX (Saint) on Oct 03, 2018 at 16:34 UTC | |
by bigup401 (Pilgrim) on Oct 03, 2018 at 16:49 UTC | |
by LanX (Saint) on Oct 03, 2018 at 17:15 UTC | |
by bigup401 (Pilgrim) on Oct 04, 2018 at 08:00 UTC | |
|
Re: sql join with multiple select
by AnomalousMonk (Archbishop) on Oct 04, 2018 at 18:07 UTC | |
|
Re: sql join with multiple select
by Corion (Patriarch) on Oct 05, 2018 at 13:48 UTC |