function item_to_id($value, $table, $column = 'name', $url_col = '') {
$value = addslashes($value);
$sql = "SELECT id FROM $table WHERE $column = '$value' LIMIT 1";
$result = runQuery($sql);
if (mysql_num_rows($result)) {
$row = mysql_fetch_assoc($result);
return $row['id'];
} else {
if ($url_col) {
$url = nukeUrlSafe($value);
$sql = "INSERT INTO $table SET $column = '$value', $url_col = '$url'";
runQuery($sql);
return mysql_insert_id();
} else {
$sql = "INSERT INTO $table SET $column = '$value'";
runQuery($sql);
return mysql_insert_id();
}
}
}
function pagify_results($sql, $letter, $songs) {
$result = runQuery($sql);
if (mysql_num_rows($result)) {
$per_page = 50;
if ($_GET['page'] > 0) {
$page = $_GET['page'] + 0;
} else {
$page = 1;
}
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
$first_item = $per_page * ($page - 1);
$sql .= " LIMIT $first_item, $per_page";
$result = runQuery($sql);
$max_this_page = $first_item + $per_page;
if ($max_this_page > $total_results)
$max_this_page = $total_results;
echo "<h2>Displaying ".($first_item+1)." to $max_this_page of $total_results Results</h2>\n";
$pre_pagify = "";
for ($i = 1; $i <= $total_pages; $i++) {
if ($page == $i)
$pre_pagify .= "<a href='?page=$i'><strong>$i</strong></a> ";
else
$pre_pagify .= "<a href='?page=$i'>$i</a> ";
}
$pre_pagify .= "";
$pagify = "<div class='pagify'>";
if ($page > 1) {
$pagify .= "<a href='?page=1'>First</a> | <a href='?page=". ($page - 1) . "'>Prev</a> | ";
} else {
$pagify .= "First | Prev | ";
}
#$pagify .= " <b style='color: #444;'>Page " . $page . " / " . $total_pages . "</b> | ";
if (!$songs)
$pagify .= $pre_pagify;
else
$pagify .= $page . " / " . $total_pages;
if ($page < $total_pages) {
$pagify .= " | <a href='?&page=". ($page +1) . "'>Next</a> | <a href='?page=". ($total_pages) . "'>Last</a>";
} else {
$pagify .= " | Next | Last";
}
$pagify .= "</div>\n";
echo $pagify;
?>
<ul>
<?php
$sql = "SELECT s.name AS song_name, s.url AS song_url, s.submit_name, s.submit_time, a.name AS artist_name, a.url AS artist_url FROM song AS s, artist AS a WHERE s.artist_id = a.id ORDER BY s.id DESC LIMIT 20";
$result = runQuery($sql);
while ($row = mysql_fetch_assoc($result)) {
?>
<li><a href="lyrics-<?=$row['artist_url']?>-<?=$row['song_url']?>.htm"><?=trimmer($row['artist_name'] . " - " . $row['song_name'],30)?></a></li>
<li>By <em><?=$row['submit_name']?></em> approx <?=tPass(strtotime($row['submit_time']))?> ago</li>
<?php
}
?>
</ul>
Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.