Goke Aruna wrote:
> Can someone be of help;
>
> I have the code below, what i wanted this code to do is to dynamically
> create fields to select and again to dynamically subtitute the value of the
> given fields.
>
> my sms content is the source of my data and my table definition is as below:
>
> (Id int auto_increment primary key,
> Name varchar(32),
> TradeName varchar(20),
> Address varchar(50),
> City varchar(13)
> State varchar(10),
> phone varchar(30),
> IndType varchar(20)
> );
>
> user can determine their known and unknown fields as they like.. I should be
> able to know which fields to select and which fields is supplied by the
> user.
>
> Thanks
>
> goksie
>
>
> #!/usr/bin/perl
> #
> use warnings;
> use strict;
> use DBI;
>
> my ($dsource, $user, $pass, $ret, $sql, $dbh, $sth, $row, $port, $hostname,
> $database, $data);
> $user='test'; ## user sade need select only access to the table
> yellopgdb.yellopg
> $pass='test123';
> $port='3306';
> my $name='localhost';
> $dsource="dbi:mysql:yellopgdb:$name";
> $dbh = DBI->connect( $dsource, $user, $pass )|| die ("Couldn't connect to
> yellopgdb !\n");
>
>
> #user supplies name unknown, address unknown,
> #
> #user send sms to myphonenumber with content tradename,onet city,ibadan
> #name,query phone,query indtype,query
> #
>
> my $smscontent =
> "tradename,onet,city,ibadan,name,query,phone,query,indtype,query";
> my %sms =split(/,/, $smscontent);
> my @smswanted =();
> my @given =();
> #
> foreach(keys %sms){
> push @smswanted, $_ if $sms{$_} eq 'query';
> push @given, $_, $sms{$_} if $sms{$_} ne 'query';
> }
>
> =begin
> $cname = $coy{'name'};
> $ctradename = $coy{'tradename'};
> $caddress = $coy{'address'};
> $ccity = $coy{'city'};
> $cstate = $coy{'state'};
> $cphone = $coy{'phone'};
> $cindtype = $coy{'indtype'};
> =end
> =cut
>
> my $qry = "select $smswanted[0],$smswanted[1],$smswanted[2] from yellopg
> where $given[0]=? and $given[2]= ?";
> $sth = $dbh->prepare($qry);
> $sth->execute($given[1], $given[3]);
> my @userinfo = $sth->fetchrow_array;
> print @userinfo;
What is your question?
The code you have written looks like it should work. Are you having problems
with it? Where do you want to go from here?
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/