#!/usr/bin/env perl use strict; use warnings; #use Mojo::SQLite; use Mojolicious::Lite; use DBI; #hypnotoad app->config( hypnotoad => { listen => [ 'http://127.0.0.1:8083/' ], proxy => 1, }, ); # interact with database my $dbh = DBI->connect("dbi:SQLite:mydb.db","","") or die "Could not connect"; helper db => sub { $dbh }; #get '/' => { text => q{ #
#}}; #my $query=param(q); #how to pass 'John Doe' as a variable from the user input helper select => sub { my $self = shift; my $sth = eval { $self->db->prepare('SELECT * FROM contacts where name like '%John AND Doe%'') } || return undef; $sth->execute; return $sth->fetchall_arrayref; }; app->select; # setup route, such that search query gets appended to root in the output, e.g., /John Doe for 'John Doe' search query. How to connect 'param(q)' and ':query'? get '/:query' => sub { my $self = shift; my $query=param(q); my $rows = $self->select; $self->stash( rows => $rows ); $self->render('index'); }; app->start; __DATA__ @@ index.html.ep Emp


% foreach my $row (@$rows) { % foreach my $text (@$row) { % } % }
id name department
<%= $text %>