Yes it is possible, I have that feature on my website. My site is AJAX based so, my script would not work you. However I will share so you will have some idea how to do it.
I created a table in SAMDB called song_comments
Song comments appear and are entered on the Now Playing page:
Code:
//Get Song Comments
$comments_rows = mysqli_query( $samDB, "Select comments, username, create_date from song_comments WHERE deleted_flag=0 and songid in ( " . $now_playing["song_id"] . " ) order by id desc" );
<!-- Song Comments -->
<tr>
<td><hr/></td>
</tr>
<tr>
<td>
<div id="comments">
<div style="display:inline"><b>Song Comments:</b></div>
<ul>
<?php
$c=0;
$nameArray = Array();
while ( $row = mysqli_fetch_assoc( $comments_rows ) ) {?>
<li><?php echo( date( $configuration->date_time_format, strtotime( $row["create_date"] ) ) );
echo " - <b>";
echo( $row["username"] );
echo "</b> wrote ";
echo "<i>\"";
echo( stripslashes(str_replace("&quot;", "'",$row['comments'])));
echo "</i> \""?>
</li>
<?php
$nameArray[] = $row["username"];
$c++; } ?>
</ul>
<? if($c == 0 ) { ?>
No song comments posted yet
<?php } ?>
<br/>
<b>
<font color="green" size=1>
Comments are the opinions of the users/listeners who post them and do not represent the views or opinions of 5280 Light Jazz.
<br/>
</font>
</b>
<?php if ((sizeof($nameArray) == 0 || !in_array($username, $nameArray)) && $is_registered) {
?>
<div style="display:inline"><b>Enter Song Comments:</b></div>
<div id="expander9" style="display:inline">
<a href="javascript:expandBlock(9);" title="Expand this block">[+]</a>
</div>
<div id="item9" style="display:none">
<form name="theSongForm" action="#" method="post">
<textarea id="comment" cols="30" rows="8"></textarea>
<br>
<font face="Verdana, Arial, Helvetica" size="1">
Maximum comment is 200 characters
</font>
<br>
<input type='hidden' id='song_id' value="<?php echo $now_playing["song_id"];?>">
<INPUT TYPE="button" Value="Submit Comments" onClick="javascript:doComment(document.getElementById('comment').value, document.getElementById('song_id').value);">
<input type="button" Onclick="javascript:alert('Comment length:\n' + document.theSongForm.comment.value.length + ' character(s)');" value="Check length">
</form>
</div>
<?php }?>
</div>
</td>
</tr>
<tr>
<td><hr/></td>
</tr>
<!-- End Song Comments -->
This script processes the input for song comments and is called comments.php
Code:
<?php
define( "IN_5280Jazz", true );
require_once( "include/setup.php" );
if ( !$is_registered )
{
exit();
}
$comments = $_POST["comments"];
$the_id = $_POST["id"];
$mode = $_POST["mode"];
if (isset($comments)) {
$comments = mysqli_real_escape_string( $samDB, $comments);
if (strlen($comments) <= 0) {
$mode = "error";
$error_message = "No comment!";
}
if (strlen($comments) > 200) {
$mode = "error";
$error_message = "Comment too large!";
}}
$comment_row = mysqli_query( $samDB, "Select comments from song_comments WHERE userid = ( " . $user->data['user_id'] . " ) and songid = ".$the_id." " );
$dup_check = mysqli_fetch_assoc( $comment_row );
if ( $dup_check['comments'] == "" ) {
if(( $mode == "add" ) && (isset( $comments )) ) {
$insertTime = time();
mysqli_query( $samDB, "INSERT into song_comments (comments, create_date, username, songid, userid) VALUES ('$comments', '" . date("Y-m-d H:i:s", $insertTime) . "', '$username', '$the_id', " . $user->data['user_id'] . ")" );
}
}
$comments_rows = mysqli_query( $samDB, "Select comments, username, create_date from song_comments WHERE deleted_flag=0 and songid = ".$the_id." order by id desc" );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Song Comments</title>
<meta charset="utf-8"/>
</head>
<body>
<div style="display:inline"><b>Song Comments:</b></div>
<ul>
<?php
$c=0;
$nameArray = array();
while ( $row = mysqli_fetch_assoc( $comments_rows ) ) {?>
<li><?php echo( date( $configuration->date_time_format, strtotime( $row["create_date"] ) ) );
echo " - <b>";
echo( $row["username"] );
echo "</b> wrote ";
echo "<i>\"";
echo stripslashes($row['comments']);
echo "</i> \""?>
</li>
<?php
$nameArray[] = $row["username"];
$c++; } ?>
</ul>
<? if($c == 0 ) { ?>
No song comments posted yet
<?php } ?>
<br/>
<b>
<font color="green" size=1>
Comments are the opinions of the users/listeners who post them and do not represent the views or opinions of 5280 Light Jazz.
<br/>
</font>
</b>
<?php if (sizeof($nameArray) == 0 || !in_array($username, $nameArray)) {
?>
<div style="display:inline"><b>Enter Comments:</b></div>
<div id="expander9" style="display:inline">
<a href="javascript:expandBlock(9);" title="Expand this block">[+]</a>
</div>
<div id="item9" style="display:none">
<form name="theForm" action="#" method="post">
<textarea id="comments" cols="50" rows="5"></textarea>
<br>
<font face="Verdana, Arial, Helvetica" size="1">
Maximum comment is 200 characters
</font>
<br>
<input type='hidden' id='mode' value="add">
<input type='hidden' id='song_id' value="<?php echo $now_playing["song_id"];?>">
<INPUT TYPE="button" Value="Submit Comment" onClick="javascript:doComment(document.getElementById('mode').value, document.getElementById('comments').value, document.getElementById('song_id').value);">
<input type="button" Onclick="javascript:alert('Comment length:\n' + document.theForm.comments.value.length + ' character(s)');" value="Check length">
</form>
</div>
<?php }?>
</body>
</html>
<?php require_once( "include/teardown.php" ); ?>
This is the AJAX code:
Code:
function doComment( comment, song_id )
{
var mode = 'add';
new Ajax.Request('comments.php',
{
method:'post',
parameters: {fhr_time: getFHRTime(), mode: mode, comments: comment, id: song_id},
onSuccess: function(transport)
{
var response = transport.responseText || "no response";
new Effect.Fade( "comments",
{ afterFinish: function ()
{
document.getElementById( "comments" ).innerHTML = response;
new Effect.Appear( "comments" );
}
});
}
});
}