Jump to content

Help D:

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
I'm trying to design a system where someone can 'Follow' a person

And then if the person the other person is following they can then 'Fully Follow' the user.

It's working with a database and 5 tables

followfrom
followto
fullfollow
fullnamefrom
fullnameto

I want the system to do this.

1) If neither users are following one another, then display Follow for each user
2) If one user is following the other, display Follow Back, and nothing for the user Following already
3)If both users are fully following, display nothing for each user

I just can't crack it D:

Here is the code



if (isset($_COOKIE["user"])){


$sql = "SELECT * FROM follow WHERE followto = '$id'";

$query = mysql_query($sql) or die(mysql_error());

		

if(mysql_num_rows($query) < 1) {

	

if($row['followto'] == $id){ }else{

	

echo " <div class='nav'>

 <form action='newfollow.php' method='post'>

 <input type='hidden' value='".$id."' name='linkto'>

 <input type='hidden' value='".$_COOKIE['user']."' name='linkfrom'>

  <input type='hidden' value='".$row['fullname']."' name='fullnameto'>

<input type='submit' value='Follow' class='fb9' name='submit'> 

</form>

</div>";


}


}else{

		

if($row['fullfollw'] == 0){


echo "<div class='nav'>

 <form action='fullfollow.php' method='post'>

<input type='submit' value='Follow Back' class='fb9' name='submit'> 

</form>

</div>";


 }else{ }


}

	

}




#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
Follow who, how and where? see if user x has clicked the same links in a row? or what are you thinking of?
or do you want to let users subscribe to other users pages? or anything else?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
This is all internally on a system I'm building

It allows users to create profiles

Then you can 'Follow' & 'Fully Follow' users

1) If neither users are following one another, then display Follow for each user
2) If one user is following the other, display Follow Back, and nothing for the user Following already
3)If both users are fully following, display nothing for each user

#4
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Hmm, first $row['fullfollw'] shouldn't that be $row['fullfollow']? And did you mean those were the table fields ( not tables ) ? (followto, followfrom, etc. )

If so, I dunno why you'd need a field 'fullfollow' because isn't that just the sum of having a row where followto = user1 and followfrom = user2 and a row where followto = user2 and followfrom = user1?






Just if I get you right, then you could just have a code like this:

$user = "user1"; //cookie or whatever contains the username or id
$target_user = "user2"; //the target user that the loggedin user can follow/full follow?
$check_follow = mysql_query("SELECT * FROM follow WHERE followto = '$user' AND followfrom = '$target_user' "); //is target user already following loggedin user?
 
if(mysql_num_rows($check_follow) > 0) {
   $check_follow_full = mysql_query("SELECT * FROM follow WHERE followto = '$target_user' AND followfrom = '$user' "); //is loggedin user ALSO already following target user back?
   if(mysql_num_rows($check_follow_full) > 0) {
       //they're full following, show nothing?
   }else{ 
       //not full following yet, show full follow 
       echo "Full follow"; //..
   }
}else{
      //not followed yet at all, show follow
      echo "Follow";
}
 
?>

Just small example because Im not sure if I get you right, let me know.

#5
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
This looks correct

Although if the user was fully following already, how would I get that to then display nothing? As there would be no need for a button

#6
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
<?php
 
$user = "user1"; //cookie or whatever contains the username or id
$target_user = "user2"; //the target user that the loggedin user can follow/full follow?
$check_follow = mysql_query("SELECT * FROM follow WHERE followto = '$user' AND followfrom = '$target_user' "); //is target user already following loggedin user?
 
if(mysql_num_rows($check_follow) > 0) {
   $check_follow_full = mysql_query("SELECT * FROM follow WHERE followto = '$target_user' AND followfrom = '$user' "); //is loggedin user ALSO already following target user back?
   if(mysql_num_rows($check_follow_full) > 0) {
       //they're full following, show nothing?
   }else{ 
       //not full following yet, show full follow 
       echo "Full follow"; //..
   }
}else{
 
      /* Updated this part for that */
 
      $check_follow = mysql_query("SELECT * FROM follow WHERE followto = '$target_user' AND followfrom = '$user' ");
      if(mysql_num_rows($check_follow) == 0) { //not already following target user?
      //not followed yet at all, show follow
      echo "Follow";
      }
}
 
?>  
</SPAN>

Updated the main else loop.

Though might be able to be coded some more efficient but just an example, hope it helps =].

btw, you could also use COUNT(*) instead of mysql_num_rows, might be faster or something.

#7
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
I tried the code and got this error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a5064497/public_html/beta/profile.php on line 88

That is on the line

if(mysql_num_rows($check_follow) > 0) {

#8
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Edit the query $check_follow and copy paste mysql error:

$check_follow = mysql_query("SELECT * FROM follow WHERE followto = '$user' AND followfrom = '$target_user' ")or die(mysql_error());

And if it did just not return any results, you might want to just add @ to mysql_num_rows so it doesn't mention it as in an error. However first try above query to see if it returns any mysql errors.

#9
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Thank's this worked great!

#10
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Glad to hear it's working now! =]

Good luck on the further script.