Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

fetching database records using loops in per probleml

loop records

  • Please log in to reply
1 reply to this topic

#1 mutago

mutago

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 477 posts

Posted 21 December 2011 - 05:00 PM

good day everyone, am trying to print a information if the price of televison where okay but it does not print
anything. it seem i did not loop the records very well
any help please. below is the code
#!/xampp/perl/bin

$dbh = "dbi:mysql:testDB:localhost:3306"',"root","root77";

$query = "SELECT price FROM product where television='panasonic'";
$rs = $connect->prepare($query);

$rs->execute();

# BIND TABLE COLUMNS TO VARIABLES
$rs->bind_columns(undef, \$price);


# check if the price is greater than $10,000 AND this where am having prblem

if ($rs[0] > 10000) {
print  "price is greater than 10000";
}


elsif($rs[0] = 10000) {

print "correct";


}

else{
print "you get it wrong";
}


















  • 0

#2 numberwhun

numberwhun

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 03 April 2012 - 01:22 AM

First, your code tags are not complete. Your last tag should have a ] after it. Second, you do not have any loops in your code. You have an if statement and are testing the current value of $rs[0], assuming it has a value, but there are no loops present in your code.

I first recommend that you add the following pragmas to your code after the shebang line:

use strict;
use warnings;

Every Perl script you write should have those in it to avoid putting code in here with basic syntactical issues. After that, you will need to re-write the code with a loop if you wish to loop through $rs, but even before you do that, $rs would first need to be defined as @rs. You also don't have any fetch_array uses in the code, so while you executed the statement, your not pulling any data.

You should really go through a Perl DBI tutorial to learn the proper way to use it first, and you may then understand what is going wrong with the code you have posted.

Regards,

Jeff
  • 0





Also tagged with one or more of these keywords: loop, records