Hi All,
I'm a bit new to Perl, so sorry if this question may be a bit easy. I'm used to using DBI and MySQL, but when it comes to other tricks in Perl...thats where I lack.
I'm looking foward to finding out the range between two numbers. These numbers are stored in variables so it may change at given times.
So lets say $a = 2, and $b = 8 then I want to retreive the range that would be:
2, 3, 4, 5, 6, 7 , 8
I would like this to be in some sort of array list so I can use these numbers inside a MySQL select statement.
I have this mysql table that includes numbers and a type of dog. :)
| numbers | type |
-------------------
| 2 | ac |
| 3 | dc |
| 4 | ca |
| 4 | md |
| 5 | ae |
| 6 | ce |
| 7 | da |
| 8 | ac |
___________________
I need some sort of way to display the values in column type by using the range of numbers. So if the range was 2-8, I would need to display all those values listed on the above table. Notice how it shows the number 4 twice , both having different values.
I'm not sure if I should just do a foreach statement and use the array range to find out all the values for each number. for ex.
my $type;
my $sth = $dbh->prepare_cached(<<SQL);
SELECT type from dogs where number = ?
SQL
foreach $number (@num_range) {
$sth->execute($number);
$sth_x->bind_columns(undef, \$type);
while ($sth->fetch) {
print "$num: $type";
}
}
Is this the best way to do this, or is there a better way to do this in a MySQL syntax? And if it is the best way, then I wouldn't know how to calculate the number range :(!!!
Any suggestions is greatly appreciated.
Thank you.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.