pb pour creer un vote dans un site

pb pour creer un vote dans un site - PHP - Programmation

Marsh Posté le 15-10-2008 à 18:35:33    

Bonjours,
 
Depuis des semaines avec un ami on arrive pas a creer des votes pour des photos dans un site. Dans cette page en construction  http://naturescience.free.fr/oiseaux_vote.php :
 
- Pourquoi des la 20ème photo on a le message fatale error... et plus de vote puis la photo suivante decallée ??
 
- Pourquoi a la 2ème et 3ème ligne de photos les etoiles des votes realiser sont il decalées vers la droite suivant les etoiles pour voter ?
 
- Comment peut on eliminer la marche de gauche qu'on a dès qu'on enregistre le fichier du HTML en php alors qu'en HTML on a pas cette marge ?
 
Merci
 
Williams

Reply

Marsh Posté le 15-10-2008 à 18:35:33   

Reply

Marsh Posté le 15-10-2008 à 23:22:48    

Pour avoir plus d'info :
 
- J'ai mis une table :
 
CREATE TABLE `createdtablename` (
`id` varchar(11) NOT NULL,
`total_votes` int(11) NOT NULL default '0',
`total_value` int(11) NOT NULL default '0',
`average` float(5,2) NOT NULL default '0',
`which_id` int(11) NOT NULL default '0',
`used_ips` longtext,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;
 
 
- Au site que j'avais fait en HTML qui n'avais de pb de marge ou photo decaler, j'ai entré cette ligne en haut de la page où tu veux avoir des tes étoiles ( tout en haut avant n'importe qu'elle balises) : <? php require ( '_drawrating.php');?> ;
 
- Entre <head> et </head> j'ai copié les lignes Javascript et link ci dessous.
<script type="text/javascript" language="javascript" src="js/behavior.js"> </ script>
<script type="text/javascript" language="javascript" src="js/rating.js"> </ script> ;
 
- Sous chaque photo je mets : <p><font color="#000000"><b>Votez :</b>  
<?php echo rating_bar('1','5'); ?>
Dont je change le numero qui est 1 pour ici " ('1','5'); " pour chaque photo
 
Ceci peu peut etre t'aider pour voir.
 
Williams

Reply

Marsh Posté le 19-10-2008 à 11:48:46    

Je suis etonné que 4 jours apres personne n'ai repondu malgres qu'il y a des prof. dans le forum  :(  
 
Le pb viendrait d'apres ce qu'on m'a dit du fichier  _drawrating.php dont voici le code :
 
<?php
/*
Page: _drawrating.php
Created: Aug 2006
Last Mod: Mar 18 2007
The function that draws the rating bar.
---------------------------------------------------------  
ryan masuga, masugadesign.com
ryan@masugadesign.com  
Licensed under a Creative Commons Attribution 3.0 License.
http://creativecommons.org/licenses/by/3.0/
See readme.txt for full credit details.
--------------------------------------------------------- */
function rating_bar($id,$units='',$static='') {
 
require('_config-rating.php'); // get the db connection info
 
//set some variables
$ip = $_SERVER['REMOTE_ADDR'];
if (!$units) {$units = 10;}
if (!$static) {$static = FALSE;}
 
// get votes, values, ips for the current rating bar
$query=mysql_query("SELECT total_votes, total_value, used_ips FROM $rating_dbname.$rating_tableName WHERE id='$id' " )or die(" Error: ".mysql_error());
 
 
// insert the id in the DB if it doesn't exist already
// see: http://www.masugadesign.com/the-la [...] omment-121
if (mysql_num_rows($query) == 0) {
$sql = "INSERT INTO $rating_dbname.$rating_tableName (`id`,`total_votes`, `total_value`, `used_ips`) VALUES ('$id', '0', '0', '')";
$result = mysql_query($sql);
}
 
$numbers=mysql_fetch_assoc($query);
 
 
if ($numbers['total_votes'] < 1) {
$count = 0;
} else {
$count=$numbers['total_votes']; //how many votes total
}
$current_rating=$numbers['total_value']; //total number of rating added together and stored
$tense=($count==1) ? "vote" : "votes"; //plural form votes/vote
 
// determine whether the user has voted, so we know how to draw the ul/li
$voted=mysql_num_rows(mysql_query("SELECT used_ips FROM $rating_dbname.$rating_tableName WHERE used_ips LIKE '%".$ip."%' AND id='".$id."' " ));
 
// now draw the rating bar
$rating_width = @number_format($current_rating/$count,2)*$rating_unitwidth;
$rating1 = @number_format($current_rating/$count,1);
$rating2 = @number_format($current_rating/$count,2);
 
 
if ($static == 'static') {
 
$static_rater = array();
$static_rater[] .= "\n".'<div class="ratingblock">';
$static_rater[] .= '<div id="unit_long'.$id.'">';
$static_rater[] .= '<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
$static_rater[] .= '<li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
$static_rater[] .= '</ul>';
$static_rater[] .= '<p class="static">'.$id.'. Rating: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast) <em>This is \'static\'.</em></p>';
$static_rater[] .= '</div>';
$static_rater[] .= '</div>'."\n\n";
 
return join("\n", $static_rater);
 
 
} else {
 
$rater ='';
$rater.='<div class="ratingblock">';
 
$rater.='<div id="unit_long'.$id.'">';
$rater.=' <ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
$rater.=' <li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
 
for ($ncount = 1; $ncount <= $units; $ncount++) { // loop from 1 to the number of units
if(!$voted) { // if the user hasn't yet voted, draw the voting stars
$rater.='<li><a href="db.php?j='.$ncount.'&amp;q='.$id.'&amp;t='.$ip.'&amp;c='.$units.'" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';
}
}
$ncount=0; // resets the count
 
$rater.=' </ul>';
$rater.=' <p';
if($voted){ $rater.=' class="voted"'; }
$rater.='>'.$id.' Rating: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast)';
$rater.=' </p>';
$rater.='</div>';
$rater.='</div>';
return $rater;
}
}
?>
 
On m'a consellé de remplacer :
 
$rating_width = @number_format($current_rating/$count,2)*$rating_unitwidth;
$rating1 = @number_format($current_rating/$count,1);
$rating2 = @number_format($current_rating/$count,2);
 
PAR
 
$rating_width = ($count == 0) ? 0 : @number_format($current_rating/$count,2)*$rating_unitwidth;
$rating1 = ($count == 0) ? 0 : @number_format($current_rating/$count,1);
$rating2 = ($count == 0) ? 0 : @number_format($current_rating/$count,2);
 
Mais voila qu'apres avoir fait ceci, sur les 2 fichiers qui represente la meme chose pour des essaies, à http://naturescience.free.fr/oiseaux1.php les vote n'ont pas lieu, sur le fichier http://naturescience.free.fr/oiseaux_vote.php il n'affiche plus rien maintenant (donc pire) et dit que la table n'existe pas alors que precedemment il disait pas ceci alors que je n'ai rien touche a cette table.
 
Je ne comprends rien. D'ou viens ces pb ??
 
Merci
 
Williams
 

Reply

Marsh Posté le 22-10-2008 à 22:37:47    

Pourquoi 7 jours il y a pas de reponse ?
 
Williams

Reply

Marsh Posté le 23-10-2008 à 09:50:01    

Bonjour,
 
L'erreur sur ton site appelle la table createtablename et ton petit script SQL crée une table createdtablename, il y a donc bel et bien une incohérence et mySQL a raison de ne pas trouver la table.
 
Ensuite c'est pas parce qu'un fichier HTML deviens un fichier PHP que ça rajoute des marge à gauche à la div tartempion rien que pour t'embetter... Cela n'as aucun rapport, tu as du au passage modifier des style CSS ou activer du javascript qui modifie les positionnements des éléments HTML de la page.
 
La correction que les gens t'ont conseillée est bonne, cela évite une division par zéro (ce qui est mathématiquement impossible) tu peut donc la conserver.
 
Bref commence par déjà résoudre le problème de tablename et reviens ensuite.
 
A+

Reply

Marsh Posté le 23-10-2008 à 14:44:19    

la ca me parrait louche :  

Code :
  1. $static_rater = array();
  2. $static_rater[] .= "\n".'<div class="ratingblock">';
  3. $static_rater[] .= '<div id="unit_long'.$id.'">';
  4. $static_rater[] .= '<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
  5. $static_rater[] .= '<li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
  6. $static_rater[] .= '</ul>';
  7. $static_rater[] .= '<p class="static">'.$id.'. Rating: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast) <em>This is \'static\'.</em></p>';
  8. $static_rater[] .= '</div>';
  9. $static_rater[] .= '</div>'."\n\n";


 
pk creer un tableau, concatener des valeurs alors que le chainesera vide car tu ajoutes une ligne à chaque fois avec "[]"

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed