like button tutorial trouble

Post here is you are having problems with any of the tutorials.
Post Reply
Thunderbob
Posts: 46
Joined: Sat Jun 30, 2012 12:31 pm

like button tutorial trouble

Post by Thunderbob »

So on my site a user as a "wall" where they can post status updates and other people can post a comment on their wall.
The issue is that the like button refreshes the page and the user has to scroll all the way back down just to pick up where they left off. This can be quite frustrating for users when I want to incorporate this on something more extensive :lol:

I quickly began the like button tutorial but again the refresh issue.

code

[syntax=php]<h3><table width="800" border="0"> </h3>

<form name="form2" method="post" action="" >
<?php echo $likerror; ?>
<?php if($profileOwner):?><div style="text-align:left;"><input type="submit" name="remove" id="remove" value="Delete Posts" /></div><?php endif;?>
<tr style="text-decoration:underline; font-weight:500; font-size:x-large;" >
<td width="50" height="50" align="center"></td>
</tr>
<?php
while($rows = mysql_fetch_array($result9)){

?>

<tr>
<td width="41" align="center"><?php if($profileOwner):?><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $rows['id']; ?>" /> <?php endif;?></td>
<td width="750">

</h4></a><br>
<h5><?php echo $rows['message']; ?> </h5><br>
<?php echo $rows['date']; ?>

<div width="30px" style="background:#282828; color: white; font-weight: bold; font-size: 14pt; text-align:center; margin-left: 560px; border-radius: 7px; padding-right: 1px; padding-top: 4px; margin-top: -35px; ">
<a href="" onclick="like_add(', $rows['id'], ');"><img SRC="/images/icons/like.gif" HEIGHT="25" WIDTH="25" style="position:relative;"></a> <?php echo $rows['likes']; ?> Likes </div>
<script type ="text/javascript" src="/js/like.js"></script>
<script type ="text/javascript" src="/js/jquery.js"></script>
<input type="hidden" name="replyto" id="replyto" value="<?php echo $username; ?>"/>
<input type="hidden" name="id" id="replyid" value="<?php echo $user_id ?>"/>
<input type="hidden" name="myid" id="myid" value="<?php print $myid; ?>"/>
<input type="hidden" name="postdate" id="postdate" value="<?php print date("m.d.y"); ?>"/>
<hr></td>
<td width="70" align="center"><a href="profile.php?uid=<?php echo $rows['fromid']; ?>"><?php echo $rows['fromuser']; ?></a>
<br><img src="/members/<?php echo $rows['imagelocation']; ?>/profile_image.jpg" width="50px" height="75px">

</td>

</tr>
<tr>
<td colspan="3" align="center">

<?php }


if($_POST['Post']){
$fromidpost = $_POST['myid'];
$replyuser = $_POST['replyto'];
$replysubject = $_POST['replysubject'];
$comments = $_POST['comments'];
$postdate = date("m.d.y");
$theirid = $_GET['uid'];




$query = mysqli_query($myConnection, "INSERT INTO `wall` (fromid, fromuser, toid, touser, message, date, wallid, imagelocation) VALUES ('$myid', '$myusername', '$theirid', '$username', '$comments', '$postdate', '$theirid','$myid')") or die (mysqli_error($myConnection));




header("Location: http://www.yourtechview.com/source/prof ... d=$user_id");


}
if($_POST['remove']){
$deleterror = lol;
$checkbox1 =$_POST['checkbox'];
$delete = $_POST['checkbox'];
if($delete) {
for($i=0;$i<$count;$i++)
{$delpos = $checkbox1[$i];

$sql = "DELETE FROM wall WHERE id='$delpos'";
$result = mysql_query($sql);
echo mysql_error();
}
if($result){ ?>
<?php if (!$checkbox){echo $deleterror;} ?>

<?php
header("Location: http://www.yourtechview.com/source/prof ... d=$user_id");
exit;
}
}
mysql_close();
}
else
{
}
if($_POST['Update']){

$replyuser = $_POST['replyto'];
$replysubject = $_POST['replysubject'];
$comments = $_POST['comments'];
$postdateu = date("m/d/y");
$theirid = $_POST['replyid'];


$query = mysqli_query($myConnection, "INSERT INTO `wall` (fromid, fromuser, toid, touser, message, date, wallid, imagelocation) VALUES ('$user_id', '$username', '$user_id', '$replyuser', '$comments', '$postdateu', '$user_id','$myid' )") or die (mysqli_error($myConnection));




header("Location: http://www.yourtechview.com/source/prof ... d=$user_id");


}




?>



</form>
</table>[/syntax]

note that the like button is within a form where the action is "post". Is this the problem and if so how do I get around it?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: like button tutorial trouble

Post by jacek »

You could give each post an ID and then redirect to that.

[syntax=php]header("Location: http://www.yourtechview.com/source/prof ... er_id#post{$theirid}");[/syntax]
when you do this the browser will scroll down to the element with the id post$theirid whcih would be something like

[syntax=php]<h3 id="post<?php echo $theirid; ?>">My post title</h3>[/syntax]
The id has to start with a letter which is why I added the "post" ;)

Also I have to mention, you should really put those queries into functions.
Image
Thunderbob
Posts: 46
Joined: Sat Jun 30, 2012 12:31 pm

Re: like button tutorial trouble

Post by Thunderbob »

hmm it seems to work somewhat.
It redirects it to the general area of where the post should be on the page but if I'm
looking at a long list of items, it will still require me to scroll up to see the post I left off on.

Also this does not work with firefox and internet explorer.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: like button tutorial trouble

Post by jacek »

Thunderbob wrote:It redirects it to the general area of where the post should be on the page but if I'm
looking at a long list of items, it will still require me to scroll up to see the post I left off on.

It will put the element with that ID just visible at the top of the screen, this is done on the HTML as it loads so if you add things with JavaScript or have images that make the page expand that can break it.

Thunderbob wrote:Also this does not work with firefox and internet explorer.

It does, fix your HTML :P
Image
Post Reply