3raser Posted April 20, 2010 Share Posted April 20, 2010 if ($comments==1) { //display data $get = mysql_query("SELECT * FROM users WHERE username='$output'"); while ($row = mysql_fetch_assoc($get)) { // get data $id = $row[id]; } //max displayed per page $per_page = 8; //get start variable $start = $_GET['start']; //count records $record_count = mysql_num_rows(mysql_query("SELECT * FROM profilecomments WHERE touser='$username'")); //count max pages $max_pages = $record_count / $per_page; //may come out as decimal if (!$start) $start = 0; //display data $get = mysql_query("SELECT * FROM profilecomments WHERE touser='$output' ORDER BY id DESC LIMIT $start, $per_page"); while ($row = mysql_fetch_assoc($get)) { if ($row[reported]==1) { $reporttext = "[Report]"; } else { $reporttext = "Message Reported"; } if ($row[hidden]==1) { $row['message']="<span style='color:blue'><i>This post has been hidden by the profile owner.</i></span>"; } echo "<b><span style='color:black'>Posted by <a href='profiles.php?search=". $row[fromuser] ."'>". $row[fromuser] ."</a> on ". $row[date] . ($userrank==1 ? "<a href='profiles.php?delcomment=1&commentid=" . $row[id] . "'>[Delete Comment]</a>":"" ) . "<div align='right'>". $reportext ."</div><br></span><span style='color:orange'>". $row[message] ."</span></b><hr><br>"; } //setup prev and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='index.php?start=$prev'>Prev</a> "; //show page numbers //set variable for first page $i=1; for ($x=0;$x<$record_count;$x=$x+$per_page) { if ($start!=$x) echo " <a href='index.php?start=$x'>$i</a> "; else echo " <a href='index.php?start=$x'><b>$i</b></a> "; $i++; } //show next button if (!($start>=$record_count-$per_page)) echo " <a href='index.php?start=$next'>Next</a>"; echo "<br><br><a href='profiles.php?addcomment=". $id ."' onclick='document.getElementById(\"commentarea\").style.visibility=\"visible\"; return false;'>Add a comment</a> <div id='commentarea' style='visibility: hidden;'> <form action='profiles.php' method='POST'><input type='hidden' name='hiddenid' value='". $id ."'><textarea name='comment' maxlength='300' cols='65' rows='15'></textarea><br><br><input type='submit' value='Add comment'> or <a href='#' onclick='document.getElementById(\"commentarea\").style.visibility=\"hidden\"; this.form.hiddenid.value=\"\";'>Discard comment</a></form> </div>"; } else { //display data $get = mysql_query("SELECT * FROM users WHERE username='$username'"); while ($row = mysql_fetch_assoc($get)) { // get data $id = $row[id]; } //max displayed per page $per_page = 8; //get start variable $start = $_GET['start']; //count records $record_count = mysql_num_rows(mysql_query("SELECT * FROM profilecomments WHERE touser='$username'")); //count max pages $max_pages = $record_count / $per_page; //may come out as decimal if (!$start) $start = 0; //display data $get = mysql_query("SELECT * FROM profilecomments WHERE touser='$username' ORDER BY id DESC LIMIT $start, $per_page"); while ($row = mysql_fetch_assoc($get)) { if ($row[reported]==1) { $reporttext = "[Report]"; } else { $reporttext = "Message Reported"; } if ($row[hidden]==1) { $row['message']="<span style='color:blue'><i>This post has been hidden by the profile owner.</i></span>"; } $name = $_SESSION['loggedin']; $check_first = md5($name); if ($row[hidden]==0) { echo "<b><a href='profiles.php?hide=". $check_first ."&idhide=". $row[id] ."'>[Hide message]</a></b> "; } else { echo "<b><a href='profiles.php?unhide=". $check_first ."&idshow=". $row[id] ."'>[show message]</a></b> "; } echo "<b><span style='color:black'>Posted by <a href='profiles.php?search=". $row[fromuser] ."'>". $row[fromuser] ."</a> on ". $row[date] . ($userrank==1 ? "<a href='profiles.php?delcomment=1&commentid=" . $row[id] . "'>[Delete Comment]</a>":"" ) ."<div align='right'>". $reportext ."</div><br></span><span style='color:orange'>". $row[message] ."</span></b><hr><br>"; } } //setup prev and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='index.php?start=$prev'>Prev</a> "; //show page numbers //set variable for first page $i=1; for ($x=0;$x<$record_count;$x=$x+$per_page) { if ($start!=$x) echo " <a href='index.php?start=$x'>$i</a> "; else echo " <a href='index.php?start=$x'><b>$i</b></a> "; $i++; } //show next button if (!($start>=$record_count-$per_page)) echo " <a href='index.php?start=$next'>Next</a>"; echo "<br><br><a href='profiles.php?addcomment=". $id ."' onclick='document.getElementById(\"commentarea\").style.visibility=\"visible\"; return false;'>Add a comment</a> <div id='commentarea' style='visibility: hidden;'> <form action='profiles.php' method='POST'><input type='hidden' name='hiddenid' value='". $id ."'><textarea name='comment' maxlength='300' cols='65' rows='15'></textarea><br><br><input type='submit' value='Add comment'> or <a href='#' onclick='document.getElementById(\"commentarea\").style.visibility=\"hidden\"; this.form.hiddenid.value=\"\";'>Discard comment</a></form> </div>"; Why does it echo out if (!($start>=$record_count-$per_page)) echo " <a href='index.php?start=$next'>Next</a>"; echo "<br><br><a href='profiles.php?addcomment=". $id ."' onclick='document.getElementById(\"commentarea\").style.visibility=\"visible\"; return false;'>Add a comment</a> <div id='commentarea' style='visibility: hidden;'> <form action='profiles.php' method='POST'><input type='hidden' name='hiddenid' value='". $id ."'><textarea name='comment' maxlength='300' cols='65' rows='15'></textarea><br><br><input type='submit' value='Add comment'> or <a href='#' onclick='document.getElementById(\"commentarea\").style.visibility=\"hidden\"; this.form.hiddenid.value=\"\";'>Discard comment</a></form> </div>"; Two times when $comment is equal to 1? I can't find it anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/199186-simple-code-error-cant-find-out-why-it-echos-out-two-times/ Share on other sites More sharing options...
Gekk0 Posted April 20, 2010 Share Posted April 20, 2010 so you mean the "show next button" gets spit out twice right? well, its not a for/while/foreach statement or (from what i can see in the code snippet, within one), its just an if statement, it should not repeat that echo - my thoughts are then thats not where your problem is.. can you be more clear? Quote Link to comment https://forums.phpfreaks.com/topic/199186-simple-code-error-cant-find-out-why-it-echos-out-two-times/#findComment-1045428 Share on other sites More sharing options...
Gekk0 Posted April 20, 2010 Share Posted April 20, 2010 by the way, i wouldnt write this: { if ($row[reported]==1) { $reporttext = "[Report]"; } else { $reporttext = "Message Reported"; } if ($row[hidden]==1) { $r The keys of $row[reported] and $row[hidden] really should be put in quotes like this $row['hidden'] and $row['reported'] you do this elsewhere too Quote Link to comment https://forums.phpfreaks.com/topic/199186-simple-code-error-cant-find-out-why-it-echos-out-two-times/#findComment-1045430 Share on other sites More sharing options...
3raser Posted April 20, 2010 Author Share Posted April 20, 2010 so you mean the "show next button" gets spit out twice right? well, its not a for/while/foreach statement or (from what i can see in the code snippet, within one), its just an if statement, it should not repeat that echo - my thoughts are then thats not where your problem is.. can you be more clear? Uhm....didn't understand that. And they are already in my if statement? And why do quotes matter? o.O Quote Link to comment https://forums.phpfreaks.com/topic/199186-simple-code-error-cant-find-out-why-it-echos-out-two-times/#findComment-1045450 Share on other sites More sharing options...
3raser Posted April 20, 2010 Author Share Posted April 20, 2010 ANYONE? Quote Link to comment https://forums.phpfreaks.com/topic/199186-simple-code-error-cant-find-out-why-it-echos-out-two-times/#findComment-1045462 Share on other sites More sharing options...
Gekk0 Posted April 20, 2010 Share Posted April 20, 2010 sorry i was talking crap, i see what your trying to do now ok i dunno if this is the problem, but i certainly think its an issue //show next button if (!($start>=$record_count-$per_page)) echo " <a href='index.php?start=$next'>Next</a>"; echo "<br><br><a href='profiles.php?addcomment=". $id ."' onclick='document.getElementById(\"commentarea\").style.visibility=\"visible\"; return false;'>Add a comment</a> <div id='commentarea' style='visibility: hidden;'> <form action='profiles.php' method='POST'><input type='hidden' name='hiddenid' value='". $id ."'><textarea name='comment' maxlength='300' cols='65' rows='15'></textarea><br><br><input type='submit' value='Add comment'> or <a href='#' onclick='document.getElementById(\"commentarea\").style.visibility=\"hidden\"; this.form.hiddenid.value=\"\";'>Discard comment</a></form> </div>"; i'm assuming that IF that statement it true, you want to do those two echo's so if thats the case you need to use {} like this //show next button if (!($start>=$record_count-$per_page)) { echo " <a href='index.php?start=$next'>Next</a>"; echo "<br><br><a href='profiles.php?addcomment=". $id ."' onclick='document.getElementById(\"commentarea\").style.visibility=\"visible\"; return false;'>Add a comment</a> <div id='commentarea' style='visibility: hidden;'> <form action='profiles.php' method='POST'><input type='hidden' name='hiddenid' value='". $id ."'><textarea name='comment' maxlength='300' cols='65' rows='15'></textarea><br><br><input type='submit' value='Add comment'> or <a href='#' onclick='document.getElementById(\"commentarea\").style.visibility=\"hidden\"; this.form.hiddenid.value=\"\";'>Discard comment</a></form> </div>"; } .. Quote Link to comment https://forums.phpfreaks.com/topic/199186-simple-code-error-cant-find-out-why-it-echos-out-two-times/#findComment-1045473 Share on other sites More sharing options...
jcbones Posted April 20, 2010 Share Posted April 20, 2010 so you mean the "show next button" gets spit out twice right? well, its not a for/while/foreach statement or (from what i can see in the code snippet, within one), its just an if statement, it should not repeat that echo - my thoughts are then thats not where your problem is.. can you be more clear? Uhm....didn't understand that. And they are already in my if statement? And why do quotes matter? o.O Quotes matter, because PHP will look for the CONSTANT with that name, when it finds none, then it will try to convert it to a string. All of this eats up processing time, which slows the script down. This is completely overlooking the fact that quotes is the correct way of doing it. Quote Link to comment https://forums.phpfreaks.com/topic/199186-simple-code-error-cant-find-out-why-it-echos-out-two-times/#findComment-1045481 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.