gracais por tu respuesta mira tengo este codigo
Código PHP:
<?
$username = "mysql_username";
$password = "mysql_password";
$database = "mysql_database";
$table = "ratings";
$days = 1;
$m = 20;
$C = 6;
@mysql_connect("localhost",$username,$password);
@mysql_select_db($database);
if($_POST['action'] == "doit")
{
if($_POST['rates']>0 && $_POST['rates']<11 && !empty($_POST['rateit_id']))
{
$ip = getenv("REMOTE_ADDR");
$query = "SELECT count(*) AS num FROM ratings WHERE (datum>SUBDATE(CURRENT_DATE(),INTERVAL ".$GLOBALS['days']." DAY) AND ip='$ip' AND article='".$_POST['rateit_id']."')";
$rs = mysql_query($query) or die("LINE 17:".mysql_error());
$as = mysql_fetch_array($rs);
if($as[num]==0)
mysql_query("INSERT INTO ratings VALUES(0,'".$_POST['rateit_id']."','".$_POST['rates']."','".$ip."',NOW())") or die(mysql_error());
echo $ad[num];
}
}
function ShowForm($id,$num,$rate_me="Rate Me",$rate_it="Rate!",$class="")
{
echo '<form action="'.$GLOBALS['PHP_SELF'].'" method="post">';
echo '<select name="rates" class="'.$class.'">';
echo '<option value="x" selected>'.$rate_me.'</option>';
for($x=$num;$x>0;$x--)
echo '<option value="'.$x.'">'.$x.'</option>';
echo '</select>';
echo '<input type="hidden" name="rateit_id" value="'.$id.'">';
echo '<input type="hidden" name="action" value="doit"> ';
echo ' <input type="submit" value="'.$rate_it.'" class="'.$class.'">';
echo '</form>';
}
function NumRates($id)
{
$res = mysql_query("SELECT count(*) AS num FROM ratings WHERE article='".$id."'") or die("LINE 50:".mysql_error());
$ar = mysql_fetch_array($res);
if(empty($ar[num])) $ar[num] = "0";
return $ar[num];
}
function ShowResult($id)
{
/*
The formula for calculating the top 250 films gives a true Bayesian estimate:
weighted rank (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × C
where:
R = average for the movie (mean) = (Rating)
v = number of votes for the movie = (votes)
m = minimum votes required to be listed in the top 250 (currently 1250)
C = the mean vote across the whole report (currently 6.9)
*/
$query = "SELECT COUNT(*) as num, ((COUNT(*)/(COUNT(*)+".$GLOBALS['m']."))*AVG(rate)+(".$GLOBALS['m']."/(COUNT(*)+".$GLOBALS['m']."))*".$GLOBALS['C'].") AS rate FROM ".$GLOBALS['table']." WHERE rate>0 AND rate<11 AND article=".$id;
$res = mysql_query($query) or die("<b>LINE 74</b>:".mysql_error());
$ar = mysql_fetch_array($res);
$procent = $ar[rate];
if(empty($procent) || $procent<0) $procent=0;
echo $procent;
}
function ShowStars($id,$width=20)
{
$query = "SELECT COUNT(*) as num, ((COUNT(*)/(COUNT(*)+".$GLOBALS['m']."))*AVG(rate)+(".$GLOBALS['m']."/(COUNT(*)+".$GLOBALS['m']."))*".$GLOBALS['C'].") AS rate FROM ".$GLOBALS['table']." WHERE rate>0 AND rate<11 AND article=".$id;
$res = mysql_query($query) or die("<b>LINE 85</b>:".mysql_error());
$ar = mysql_fetch_array($res);
$procent = (int) $ar[rate]+0.5;
if(empty($procent) || $procent<0) $procent=0;
for($x=1;$x<=$procent;$x++)
echo '<img src="./gfx/star1.jpg" alt="" width="'.$width.'"/>';
$io = $ar[rate] - (int)$ar[rate];
if($io>0.49) echo '<img src="./gfx/star2.jpg" alt="" width="'.$width.'"/>';
}
?>
pero no se como acoplarlo a este otro (noticias.php)
Código PHP:
<?
$link=mysql_connect("localhost","root","");
if (!$link)
{
die('no pudo conectar al server de mysql: ' . mysql_error());
}
// Elijes tu base de datos
$db_selected = mysql_select_db('ciberespacio', $link);
if (!$db_selected) {
die ('no se pudo elegir la base: ' . mysql_error());
}
$ssql=("SELECT *,DATE_FORMAT(fecha,'%d-%m-%Y') AS mi_fecha FROM noticias ORDER BY fecha desc limit 5");
$result=mysql_query($ssql, $link);
if (!$result) {
die('Consulta invalida: ' . mysql_error());
}
//prueba poniendo primero una condicion de si tu consulta te devuelve algun resultado
if (mysql_num_rows($result)>0)
{
while ($row=mysql_fetch_array($result)){
$texto_largo =($row[contenido]);
echo "<a href='articulos.php?idnot=".$row[ID]."'>".substr($row[titulo],0,30)."...</a><hr>";
echo substr($texto_largo,0,80)."...";
echo "<br><font color='#c0c0c0'>Publicado el ".$row[fecha]."</font><br><br>";
}
mysql_free_result($result);
mysql_close();
}
else
{
echo "no tiene datos la consulta";
}
?>
haber si puedes hecharme una mano porfas