djp1988 Posted April 18, 2008 Share Posted April 18, 2008 Hello, I have a user rating system, looks like this:Checks for and entries already in the DB, if there are none:After you vote, you see this:And then when you come back onto the page you see this:but I want the first message to disappear and the finalized message to come up just after voting.Here is my script : <?php echo'<div id="Menu"> ';require_once ('../mysql_connect.php');$query = "SELECT COUNT(comment_id) AS commentsFROM comment_tripsWHERE id_of_trip=$idofthistrip";$result = mysql_query ($query, $dbc);$row = mysql_fetch_array ($result, MYSQL_BOTH);$totalcomments = "{$row['comments']}";echo '<p style="margin-top:0px;"><a href="#comment">Comments (' . $totalcomments . ')</a></p>';$query = "SELECT COUNT(member_id) AS whovotedFROM note_tripsWHERE trip_id = $idofthistrip";$result = mysql_query ($query, $dbc);$row = mysql_fetch_array ($result, MYSQL_BOTH);$totalvotes = "{$row['whovoted']}";if($totalvotes == 1){ $grammar = ' member has '; }else{ $grammar = ' members have '; }$query = "SELECT ROUND(AVG(note),1) AS AVFROM note_tripsWHERE trip_id=$idofthistrip";$result = mysql_query ($query, $dbc);$row = mysql_fetch_array ($result, MYSQL_BOTH);$note = "{$row['AV']}";if(!$note){echo "This report has not yet been evaluated, be the first !<br />";}else{echo 'Report quality: <b>' . $note . '/5</b> <small><br />(' . $totalvotes . $grammar . 'voted)</small><br />';}$userid = $_SESSION['user_id'];$note = (int) $_GET['n'];$query = "SELECT member_id, trip_id, noteFROM note_tripsWHERE member_id = $userid AND trip_id = $idofthistrip";$result = mysql_query ($query, $dbc);$row = mysql_fetch_array ($result, MYSQL_BOTH);if(!$row && $note){ if ($note <6) { $query = "INSERT INTO note_trips(note_id,trip_id,member_id,note) VALUES('',$idofthistrip,$userid,$note)"; $result = @mysql_query ($query); $row = true; $note = true; echo '<small>Thank you for voting (average will be recalculated on next page load)</small>'; } }if($row){ echo "<small>You have already voted, you gave this report {$row['note']}/5</small>"; }else{ echo "<form action=\"$thispage\" method=\"get\" id=\"note\" > <select name=\"note\" onchange=\"MM_jumpMenu('parent',this,0)\"> <option value=\"\">Rate this Report</option>\n"; $query = "SELECT id_note FROM note_name ORDER BY id_note ASC"; $result = mysql_query ($query, $dbc); while ($row = mysql_fetch_array ($result, MYSQL_BOTH)) { echo"<option name=\"note\" value=\"$thispage?n={$row['id_note']}\">{$row['id_note']}</option>\n"; } echo '</select></form>'; }echo'</div>'; ?> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2008 Share Posted April 18, 2008 You have the insert statement right in the middle of the script. Move the insert statement up so that by the time you get the number of comments the new one has already been added. Link to comment Share on other sites More sharing options...
djp1988 Posted April 18, 2008 Author Share Posted April 18, 2008 But the insert is there because the other consitions need to be true Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2008 Share Posted April 18, 2008 I guarantee you can reorganize the code so that you can do all processing before you output any HTML code. Use boolean variables to keep track of which conditions are true or false (e.g. that a row has been inserted). Link to comment Share on other sites More sharing options...
djp1988 Posted April 19, 2008 Author Share Posted April 19, 2008 Yay, okay I have recoded it a bit and re arranged the php, and it works fine, i even made my comments to insert before displaying them, if I'm honest when you said about outputting html i got confused, but I understand now, so before i query for the number of votes and calculate the average, i must have already inserted the one from the POST !!! thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.