Lines 1442-1463
sub GetDailyQuote {
Link Here
|
1442 |
$sth = C4::Context->dbh->prepare('SELECT count(*) FROM quotes;'); |
1442 |
$sth = C4::Context->dbh->prepare('SELECT count(*) FROM quotes;'); |
1443 |
$sth->execute; |
1443 |
$sth->execute; |
1444 |
my $range = ($sth->fetchrow_array)[0]; |
1444 |
my $range = ($sth->fetchrow_array)[0]; |
1445 |
if ($range > 1) { |
1445 |
# chose a random id within that range if there is more than one quote |
1446 |
# chose a random id within that range if there is more than one quote |
1446 |
my $offset = int(rand($range)); |
1447 |
my $offset = int(rand($range)); |
1447 |
# grab it |
1448 |
# grab it |
1448 |
$query = 'SELECT * FROM quotes ORDER BY id LIMIT 1 OFFSET ?'; |
1449 |
$query = 'SELECT * FROM quotes ORDER BY id LIMIT 1 OFFSET ?'; |
1449 |
$sth = C4::Context->dbh->prepare($query); |
1450 |
$sth = C4::Context->dbh->prepare($query); |
1450 |
# see http://www.perlmonks.org/?node_id=837422 for why |
1451 |
# see http://www.perlmonks.org/?node_id=837422 for why |
1451 |
# we're being verbose and using bind_param |
1452 |
# we're being verbose and using bind_param |
1452 |
$sth->bind_param(1, $offset, SQL_INTEGER); |
1453 |
$sth->bind_param(1, $offset, SQL_INTEGER); |
1453 |
$sth->execute(); |
1454 |
$sth->execute(); |
|
|
1455 |
} |
1456 |
else { |
1457 |
$query = 'SELECT * FROM quotes;'; |
1458 |
$sth = C4::Context->dbh->prepare($query); |
1459 |
$sth->execute(); |
1460 |
} |
1461 |
$quote = $sth->fetchrow_hashref(); |
1454 |
$quote = $sth->fetchrow_hashref(); |
1462 |
# update the timestamp for that quote |
1455 |
# update the timestamp for that quote |
1463 |
$query = 'UPDATE quotes SET timestamp = ? WHERE id = ?'; |
1456 |
$query = 'UPDATE quotes SET timestamp = ? WHERE id = ?'; |