Solved

modification of perl tk code

Posted on 2004-08-25
7
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

752 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