Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

modification of perl tk code

Posted on 2004-08-25
7
Medium Priority
?
212 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 1000 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
Independent Software Vendors: 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

688 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