Bonjour,

Malgré mes connaissances limitées, je tente d'insérer un système de vote par étoiles qu'on trouve partout.
Et forcément j'éprouve des difficultés à vouloir remplacer la variable Array par une commande sql pour lier l'ID de la note à l'ID du texte à noter.

Si quelqu'un peut m'aiguiller...

Merci.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
include("settings.php");
connect();
$ids=array(1,2,3); // Ca doit se passer par là. je dois dire que $ids correspond à table_texte.id
?>
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="rating.css" />
<script type="text/javascript" src="rating.js"></script>
</head>
<body>
<?php
for($i=0;$i<count($ids);$i++)
	{
		$rating_tableName     = 'ratings';
	 $id=$ids[$i];
 $q="SELECT total_votes, total_value FROM $rating_tableName WHERE id=$id";
$r=mysql_query($q);
if(!$r) echo mysql_error();
while($row=mysql_fetch_array($r))
{
	$v=$row['total_votes'];
	$tv=$row['total_value'];
	$rat=$tv/$v;
 
	}
 
 
 
	$j=$i+1;
	$id=$ids[$i];
echo'<div class="product">
           Rate Item '.$j.'
            <div id="rating_'.$id.'" class="ratings">';
                for($k=1;$k<6;$k++){
					if($rat+0.5>$k)$class="star_".$k."  ratings_stars ratings_vote";
					else $class="star_".$k." ratings_stars ratings_blank";
					echo '<div class="'.$class.'"></div>';
					}
                echo' <div class="total_votes"><p class="voted"> Rating: <strong>'.@number_format($rat).'</strong>/5 ('.$v. '  vote(s) cast) 
            </div>
        </div></div>';}
?>