DJRobThaMan
01-03-2006, 01:02 PM
I'm extremely new to mySQL scripting and am just learning the basics through necessity with a couple websites I'm currently building. I'm writing a perl script to display a list of names that are loaded into a db. I want it to display all the names that have the same first letter in the last name and I've written code something like this:
my $sth = $dbh->prepare(qq{SELECT student_first_name, student_last_name FROM `table` WHERE `student_last_name` < 'b' AND `student_last_name` > ' '});
$sth->execute();
print header();
while(my @row = $sth->fetchrow_array())
{
($ans1, $ans2) = @row;
print "$ans1 $ans2<br>\n";
}
It works, but I'm looking for a bit more efficiency, especially because I want to be able to implement it for all letters and doing it this way would involve 2 variables and changing one to two letters before the other and that sort of thing.
So in the mySQL query:
SELECT student_first_name, student_last_name FROM `table` WHERE `student_last_name` < 'b' AND `student_last_name` > ' '
I know I've been going round and round but I've finally gotten to the point (sorry). Is there a comparison operation or function that will allow me to do something like:
SELECT crap WHERE value STARTS WITH comparison_value
Thanks,
Douglas
my $sth = $dbh->prepare(qq{SELECT student_first_name, student_last_name FROM `table` WHERE `student_last_name` < 'b' AND `student_last_name` > ' '});
$sth->execute();
print header();
while(my @row = $sth->fetchrow_array())
{
($ans1, $ans2) = @row;
print "$ans1 $ans2<br>\n";
}
It works, but I'm looking for a bit more efficiency, especially because I want to be able to implement it for all letters and doing it this way would involve 2 variables and changing one to two letters before the other and that sort of thing.
So in the mySQL query:
SELECT student_first_name, student_last_name FROM `table` WHERE `student_last_name` < 'b' AND `student_last_name` > ' '
I know I've been going round and round but I've finally gotten to the point (sorry). Is there a comparison operation or function that will allow me to do something like:
SELECT crap WHERE value STARTS WITH comparison_value
Thanks,
Douglas