Here is my little bit of code sorry very new to perl and just normal copy and paste and find my way through the code
This code works great and pulls out the last 5 records that where added to the database that have a media type of 50
That all works but I want to work out what the total amount of records in the database eg
and out put the total and the last 5 records
eg
total titles in database 155
last 5 entered
title1
title2
title3
title4
title5
Like that But I keep codeing and geting the total is 5 becuase thats what my select query comes back with
So I guess I need to do another call to the SQL database but I am not sure how it adds in to my current code so any help adding
the total amount of records with media type 50 would be great
SELECT
mediatype
FROM
videodata
WHERE
Mediatype <> 50
that would return the list now I just need to count it and fee that in to my script :-) but how and where any help on this would be great becuase Ia m such a perl newbie
#!/usr/bin/perl
use strict;
use DBI;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use HTML::Template;
my $query = CGI->new();
## Define your username/password/SQL server
my $db_server = "localhost";
my $db_user = "videodb";
my $db_password = "password";
my $db_database = "VideoDB";
my $dbh = DBI->connect("dbi:mysql:$db_database:$db_server",$db_user,$db_password) || die("Can't connect");
## Create your SQL call
my $SELECT = "SELECT imdbID, title, Mediatype, created
FROM videodata
WHERE Mediatype <> '50'
ORDER BY created
DESC LIMIT 5";
my $sth = $dbh->prepare($SELECT);
$sth->execute();
my ($imdbID,$title,$MediaType,$created);
$sth->bind_columns(\($imdbID,$title,$MediaType,$created));
my @rows;
while ($sth->fetch) {
push @rows, {
imdbID => $imdbID,
title => $title,
};
}
## Define Template
my $tmpl = HTML::Template->new( filename => "sig.tmpl");
## Feed the information you got from the query (@rows) into your template
$tmpl->param(rows => \@rows);
## Print the template
print $tmpl->output;
This code works great and pulls out the last 5 records that where added to the database that have a media type of 50
That all works but I want to work out what the total amount of records in the database eg
and out put the total and the last 5 records
eg
total titles in database 155
last 5 entered
title1
title2
title3
title4
title5
Like that But I keep codeing and geting the total is 5 becuase thats what my select query comes back with
So I guess I need to do another call to the SQL database but I am not sure how it adds in to my current code so any help adding
the total amount of records with media type 50 would be great
SELECT
mediatype
FROM
videodata
WHERE
Mediatype <> 50
that would return the list now I just need to count it and fee that in to my script :-) but how and where any help on this would be great becuase Ia m such a perl newbie
Code:
#!/usr/bin/perl
use strict;
use DBI;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use HTML::Template;
my $query = CGI->new();
## Define your username/password/SQL server
my $db_server = "localhost";
my $db_user = "videodb";
my $db_password = "password";
my $db_database = "VideoDB";
my $dbh = DBI->connect("dbi:mysql:$db_database:$db_server",$db_user,$db_password) || die("Can't connect");
## Create your SQL call
my $SELECT = "SELECT imdbID, title, Mediatype, created
FROM videodata
WHERE Mediatype <> '50'
ORDER BY created
DESC LIMIT 5";
my $sth = $dbh->prepare($SELECT);
$sth->execute();
my ($imdbID,$title,$MediaType,$created);
$sth->bind_columns(\($imdbID,$title,$MediaType,$created));
my @rows;
while ($sth->fetch) {
push @rows, {
imdbID => $imdbID,
title => $title,
};
}
## Define Template
my $tmpl = HTML::Template->new( filename => "sig.tmpl");
## Feed the information you got from the query (@rows) into your template
$tmpl->param(rows => \@rows);
## Print the template
print $tmpl->output;