Jump to content

Simple code error, can't find out why it echo's out two times


Recommended Posts

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.

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?

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

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

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>";
}

 

..

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.