modification of perl tk code

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"
TPolyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sstoukConnect With a Mentor Commented:
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
 
sstoukCommented:
We can try to make these three lines into these two:

$sth->execute;
($dir) = $sth ->fetchrow_array;
0
 
TPolyAuthor Commented:
i tried both method, but there is no output.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
TPolyAuthor Commented:
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
 
sstoukCommented:
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
 
TPolyAuthor Commented:
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
 
sstoukCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.