Vizonz Posted June 26, 2010 Share Posted June 26, 2010 Basically there is a script out there for broadcasting program for music Sam for those who are familiar. Dynamic Star Rating Redux www.boedesign.com Anyway this script is a ajax php rating script that rates The music in your database problem i am having i am not a coder so trying to learn aint working so good. Basically i want to change this script so when a song loads through my now playing script i can rate each song. but as the script stands right now. when i call the rating script. its just showing one particular item. instead of grabbing the current song. so hopefully someone can help me make some edits to make it usefull for what i need it to do. i will post some of the script if there other parts needed just let me know. Now playing <? echo "<body background='$background' bgcolor='$bgcolor' link='$links' alink='$links' vlink='$link'>"; connectdbase(); $sql2="SELECT * from historylist ORDER BY ID DESC LIMIT 1"; $result2=mysql_query($sql2); $songdata=mysql_fetch_object($result2); ?><? include("Ratings/includes/rating_functions.php"); ?> <link href="Ratings/css/rating_style.css" rel="stylesheet" type="text/css" media="all"> <script type="text/javascript" src="Ratings/js/rating_update.js"></script> <script language="JavaScript1.2"><? require("songinfo_rate.js"); ?></script> <center> <strong>Artist:</strong><? echo $songdata->artist; ?> </a><br> <strong>Song:</strong> <marquee><? echo $songdata->title; ?></marquee><br> <b>Current Rating</b><br> <? echo pullRating($song["id"],true,true,true); ?> rating_functions.php function getRating($id){ $total = 0; $rows = 0; $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$id'"); if(mysql_num_rows($sel) > 0){ while($data = mysql_fetch_assoc($sel)){ $total = $total + $data['rating_num']; $rows++; } $perc = ($total/$rows) * 20; //$newPerc = round($perc/5)*5; //return $newPerc.'%'; $newPerc = round($perc,2); return $newPerc.'%'; } else { return '0%'; } } function outOfFive($id){ $total = 0; $rows = 0; $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$id'"); if(mysql_num_rows($sel) > 0){ while($data = mysql_fetch_assoc($sel)){ $total = $total + $data['rating_num']; $rows++; } $perc = ($total/$rows); return round($perc,2); //return round(($perc*2), 0)/2; // 3.5 } else { return '0'; } } function getVotes($id){ $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$id'"); $rows = mysql_num_rows($sel); if($rows == 0){ $votes = '0 Votes'; } else if($rows == 1){ $votes = '1 Vote'; } else { $votes = $rows.' Votes'; } return $votes; } function pullRating($id,$show5 = false, $showPerc = false, $showVotes = false, $static = NULL){ // Check if they have already voted... $text = ''; $sel = mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$id'"); if(mysql_num_rows($sel) > 0 || $static == 'novote' || isset($_COOKIE['has_voted_'.$id])){ if($show5 || $showPerc || $showVotes){ $text .= '<div class="rated_text">'; } if($show5){ $text .= 'Rated <span id="outOfFive_'.$id.'" class="out5Class">'.outOfFive($id).'</span>/5'; } if($showPerc){ $text .= ' (<span id="percentage_'.$id.'" class="percentClass">'.getRating($id).'</span>)'; } if($showVotes){ $text .= ' (<span id="showvotes_'.$id.'" class="votesClass">'.getVotes($id).'</span>)'; } if($show5 || $showPerc || $showVotes){ $text .= '</div>'; } return $text.' <ul class="star-rating2" id="rater_'.$id.'"> <li class="current-rating" style="width:'.getRating($id).';" id="ul_'.$id.'"></li> <li><a onclick="return false;" href="#" title="1 star out of 5" class="one-star" >1</a></li> <li><a onclick="return false;" href="#" title="2 stars out of 5" class="two-stars">2</a></li> <li><a onclick="return false;" href="#" title="3 stars out of 5" class="three-stars">3</a></li> <li><a onclick="return false;" href="#" title="4 stars out of 5" class="four-stars">4</a></li> <li><a onclick="return false;" href="#" title="5 stars out of 5" class="five-stars">5</a></li> </ul> <div id="loading_'.$id.'"></div>'; } else { if($show5 || $showPerc || $showVotes){ $text .= '<div class="rated_text">'; } if($show5){ $show5bool = 'true'; $text .= 'Rated <span id="outOfFive_'.$id.'" class="out5Class">'.outOfFive($id).'</span>/5'; } else { $show5bool = 'false'; } if($showPerc){ $showPercbool = 'true'; $text .= ' (<span id="percentage_'.$id.'" class="percentClass">'.getRating($id).'</span>)'; } else { $showPercbool = 'false'; } if($showVotes){ $showVotesbool = 'true'; $text .= ' (<span id="showvotes_'.$id.'" class="votesClass">'.getVotes($id).'</span>)'; } else { $showVotesbool = 'false'; } if($show5 || $showPerc || $showVotes){ $text .= '</div>'; } return $text.' <ul class="star-rating" id="rater_'.$id.'"> <li class="current-rating" style="width:'.getRating($id).';" id="ul_'.$id.'"></li> <li><a onclick="rate(\'1\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=1" title="1 star out of 5" class="one-star" >1</a></li> <li><a onclick="rate(\'2\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=2" title="2 stars out of 5" class="two-stars">2</a></li> <li><a onclick="rate(\'3\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=3" title="3 stars out of 5" class="three-stars">3</a></li> <li><a onclick="rate(\'4\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=4" title="4 stars out of 5" class="four-stars">4</a></li> <li><a onclick="rate(\'5\',\''.$id.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$id.'&rating=5" title="5 stars out of 5" class="five-stars">5</a></li> </ul> <div id="loading_'.$id.'"></div>'; } } // Added in version 1.5 function getTopRated($limit, $table, $idfield, $namefield){ $result = ''; $sql = "SELECT ratings.rating_id,".$table.".".$namefield." as thenamefield,ROUND(AVG(ratings.rating_num),2) as rating FROM ratings,".$table." WHERE ".$table.".".$idfield." = ratings.rating_id GROUP BY rating_id ORDER BY rating DESC LIMIT ".$limit.""; $sel = mysql_query($sql); $result .= '<ul class="topRatedList">'."\n"; while($data = @mysql_fetch_assoc($sel)){ $result .= '<li>'.$data['thenamefield'].' ('.$data['rating'].')</li>'."\n"; } $result .= '</ul>'."\n"; return $result; } rating_update.js if (document.images){ pic1 = new Image(220,19); pic1.src = "images/rating_loading.gif"; pic2 = new Image(25,75); pic2.src = "images/rating_star.gif"; pic3 = new Image(25,75); pic3.src = "images/rating_star_2.gif"; pic4 = new Image(16,13); pic4.src = "images/rating_tick.gif"; pic5 = new Image(14,14); pic5.src = "images/rating_warning.gif"; } // AJAX ---------------------------------------- var xmlHttp function GetXmlHttpObject(){ var xmlHttp = null; try { // Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } // Calculate the rating function rate(rating,id,show5,showPerc,showVotes){ xmlHttp = GetXmlHttpObject() if(xmlHttp == null){ alert ("Your browser does not support AJAX!"); return; } xmlHttp.onreadystatechange = function(){ var loader = document.getElementById('loading_'+id); var uldiv = document.getElementById('ul_'+id); if (xmlHttp.readyState == 4){ //loader.style.display = 'none'; var res = xmlHttp.responseText; //alert(res); if(res == 'already_voted'){ loader.style.display = 'block'; loader.innerHTML = '<div class="voted_twice">You already voted!</div>'; } else { loader.style.display = 'block'; loader.innerHTML = '<div class="voted">Thanks for voting!</div>'; if(show5 == true){ var out = document.getElementById('outOfFive_'+id); var calculate = res/20; out.innerHTML = Math.round(calculate*100)/100; // 3.47; //out.innerHTML = Math.round((calculate*2),0)/2; // 3.5; } if(showPerc == true){ var perc = document.getElementById('percentage_'+id); //var newPerc = Math.round(Math.ceil(res/5))*5; var newPerc = res; perc.innerHTML = newPerc+'%'; } else if(showPerc == false){ var newPerc = res; } if(showVotes == true){ var votediv = document.getElementById('showvotes_'+id).firstChild.nodeValue; var splitted = votediv.split(' '); var newval = parseInt(splitted[0]) + 1; if(newval == 1){ document.getElementById('showvotes_'+id).innerHTML = newval+' Vote'; } else { document.getElementById('showvotes_'+id).innerHTML = newval+' Votes'; } } var ulRater = document.getElementById('rater_'+id); ulRater.className = 'star-rating2'; var all_li = ulRater.getElementsByTagName('li'); // start at 1 because the first li isn't a star for(var i=1;i<all_li.length;i++){ all_li[i].getElementsByTagName('a')[0].onclick = 'return false;'; all_li[i].getElementsByTagName('a')[0].setAttribute('href','#'); } if(navigator.appName == 'Microsoft Internet Explorer'){ uldiv.style.setAttribute('width',newPerc+'%'); // IE } else { uldiv.setAttribute('style','width:'+newPerc+'%'); // Everyone else } } } else { loader.innerHTML = '<img src="images/rating_loading.gif" alt="loading" />'; } } var url = "includes/rating_process.php"; var params = "id="+id+"&rating="+rating; xmlHttp.open("POST",url,true); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Content-length", params.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(params); } Link to comment https://forums.phpfreaks.com/topic/205925-need-help-with-an-existing-script/ Share on other sites More sharing options...
Vizonz Posted June 26, 2010 Author Share Posted June 26, 2010 <? echo pullRating($song["id"],true,true,true); ?> i figure thats where i am having the problem. thats its not getting a actual song id Link to comment https://forums.phpfreaks.com/topic/205925-need-help-with-an-existing-script/#findComment-1077559 Share on other sites More sharing options...
Vizonz Posted June 26, 2010 Author Share Posted June 26, 2010 I figured it out on my own Link to comment https://forums.phpfreaks.com/topic/205925-need-help-with-an-existing-script/#findComment-1077572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.