cordoprod Posted July 18, 2008 Share Posted July 18, 2008 Hi. I have a rating system... The structure is like this: video_id | owner | views | r1 | r2 | r3 | r4 | r5 | r6 Code: if(isset($_GET['rate'])) { if($_GET['rate'] == 1 or $_GET['rate'] == 2 or $_GET['rate'] == 3 or $_GET['rate'] == 4 or $_GET['rate'] == 5 or $_GET['rate'] == 6) { if(!$_COOKIE["video_".$_GET['video'].""] and $_GET['nick'] != $_SESSION['username']) { if($_GET['rate'] == 1) $rate_row = "r1"; elseif($_GET['rate'] == 2) $rate_row = "r2"; elseif($_GET['rate'] == 3) $rate_row = "r3"; elseif($_GET['rate'] == 4) $rate_row = "r4"; elseif($_GET['rate'] == 5) $rate_row = "r5"; else $rate_row = "r6"; $new_rate = $old_rate_rows[''.$rate_row.'']+1; $rate_sql = "UPDATE travek_video_stats SET $rate_row='$new_rate' WHERE video_id='".$_GET['video']."' AND owner='".$_GET['nick']."'"; if($db->query($rate_sql)) { setcookie("video_".$_GET['video']."", true); echo "<div class=message>Din stemme ble registrert. <br>Du stemte: ".$_GET['rate']."</div><br>"; } } else echo "<div class=message>Du har allerede stemt på denne videoen.</div><br>"; } } The problem is, that it wont register rate 6. Can you see anything in my code? Link to comment https://forums.phpfreaks.com/topic/115418-solved-rating-system-help/ Share on other sites More sharing options...
cordoprod Posted July 18, 2008 Author Share Posted July 18, 2008 Does anyone know? Link to comment https://forums.phpfreaks.com/topic/115418-solved-rating-system-help/#findComment-593399 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 Well, first change this: if($_GET['rate'] == 1 or $_GET['rate'] == 2 or $_GET['rate'] == 3 or $_GET['rate'] == 4 or $_GET['rate'] == 5 or $_GET['rate'] == 6) { To this: if($_GET['rate'] > 0 && $_GET['rate'] < 7) { Does the same thing but is shorter. Now... Use a switch... if($_GET['rate'] == 1) $rate_row = "r1"; elseif($_GET['rate'] == 2) $rate_row = "r2"; elseif($_GET['rate'] == 3) $rate_row = "r3"; elseif($_GET['rate'] == 4) $rate_row = "r4"; elseif($_GET['rate'] == 5) $rate_row = "r5"; else $rate_row = "r6"; Becomes: switch($_GET['rate']){ case 1: $rate_row = "r1"; break; case 2: $rate_row = "r2"; break; case 3: $rate_row = "r3"; break; case 4: $rate_row = "r4"; break; case 5: $rate_row = "r5"; break; case 6: $rate_row = "r6"; break; } What is in $old_rate_rows? Link to comment https://forums.phpfreaks.com/topic/115418-solved-rating-system-help/#findComment-593403 Share on other sites More sharing options...
cordoprod Posted July 18, 2008 Author Share Posted July 18, 2008 Does that actually make a difference? i mean, it's the same thing just another way to do it? right? $old_rate_sql = "SELECT * FROM travek_video_stats WHERE video_id='".$_GET['video']."' AND owner='".$_GET['nick']."'"; $old_rate_res = $db->query($old_rate_sql); $old_rate_row = $db->fetchArray($old_rate_res); Link to comment https://forums.phpfreaks.com/topic/115418-solved-rating-system-help/#findComment-593408 Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 That doesn't really answer my question. I'm guessing it's a number. Oh and no it doesn't make a difference. Try changing your query to this: $rate_sql = "UPDATE travek_video_stats SET `{$rate_row}`='{$new_rate}' WHERE video_id='".$_GET['video']."' AND owner='".$_GET['nick']."'"; Also, try putting a die() above it to see that $rate_row is being set to 6. Link to comment https://forums.phpfreaks.com/topic/115418-solved-rating-system-help/#findComment-593411 Share on other sites More sharing options...
cordoprod Posted July 18, 2008 Author Share Posted July 18, 2008 works thank you Link to comment https://forums.phpfreaks.com/topic/115418-solved-rating-system-help/#findComment-593423 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.