Solved

modification of perl tk code

Posted on 2004-08-25
7
205 Views
Last Modified: 2010-03-05
Hi...
i have this perl tk code to connect to the database.
it will print the output of the search result($dir)on to the gui($text).
the problem i faced now, is that the "$dir" could not be printed out as what is being stored in the db.
instead it print out "0".

how do i modify this code.

Thanks....

Perl tk code

  $dbh = DBI->connect( 'dbi:mysql:rvsi')||
   die "Cannot connect to database: $dbh->errstr\n";
   $job=$entry->get;
   $date=$entry1->get;
   $sql = 'SELECT dir FROM tray WHERE job = "$job" AND date = "$date"';
   $sth = $dbh->prepare($sql) || die "Couldn't prepare: $dbh->errstr\n";
   $dir = $sth->execute;
   $slt="Tray Report";
   $text->delete('1.0','end');
   $text->insert('1.0',"\n\n Tray Report Result\n\n");
   $text->insert('end',"Job specification: $job\n\n");
   $text->insert('end',"Date: $date\n\n");
   $text->insert('end',"Directory path: $dir\n\n");
   print "$dir\n"
0
Comment
Question by:TPoly
  • 4
  • 3
7 Comments
 
LVL 6

Accepted Solution

by:
sstouk earned 250 total points
ID: 11899502
In Your line:
$dir = $sth->execute;

variable $dir will not contain what is stored in the database.
This only executes the query.
You have to fetch the result of the query as a hext step.

Insted of  line:
$dir = $sth->execute;

Put these lines:

$sth->execute;
my(@queryresult) = $sth ->fetchrow_array;
$dir = $queryresult[0];

And now $dir should contain the first element of your single record fetch result.
0
 
LVL 6

Expert Comment

by:sstouk
ID: 11899505
We can try to make these three lines into these two:

$sth->execute;
($dir) = $sth ->fetchrow_array;
0
 

Author Comment

by:TPoly
ID: 11899651
i tried both method, but there is no output.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:TPoly
ID: 11899888
hi sstouk...
thanks, your statement works jus that i had another error at the "$sql"
but now i solve it ..

jus want to ask another question ...
is it possible for the output to be printed on the "$text" be a link.
if possible, can you show me how??

i will increase the points if the above question is answered

 
0
 
LVL 6

Expert Comment

by:sstouk
ID: 11901882
If you display $text in a browser, then yes.
Just modify the $text so it could be a regular <A HREF=\"Address\">$text</A> HTML statement.
If you display $text in a GUI, then look through the tk controls and see if there is any control that allows the text in it to execute another action or open a different window when clicked in it, or open a Web browser, when clicked or double-clicked on the text.
Your question was not exactly a tk question. It was a database related issue.
I mostly work with database records and the Web interface but never worked with tk. Prefer Win32::GUI for simple GUI displays since my platform is Windows.
0
 

Author Comment

by:TPoly
ID: 11908894
what type of tk control thing are you talking about?
i not too sure as i'm new to perl tk too....

Mine is a gui

why is it a database issue? how to solve it?
0
 
LVL 6

Expert Comment

by:sstouk
ID: 11909500
You already solved it.
it gives you the $dir result isn't it?
That's what the original problem was:
"... the problem i faced now, is that the "$dir" could not be printed out as what is being stored in the db.instead it print out "0"."


0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now