[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

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"
0
TPoly
Asked:
TPoly
  • 4
  • 3
1 Solution
 
sstoukCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now