Jump to content

Help!

- - - - -

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
Hey guys!

Okay, what I need to do is check two db tables, the first to check if the user is 'following' somebody, the second the see what updates the person the user is following has made.

Here is the code I currently have



<?php

	$sql = "SELECT * FROM updates WHERE user = '".$userid."'";

	//Select everything from the users field where the Username is the same as the Cookie Variable

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

	while($row = mysql_fetch_assoc($query)) { 

	

	if($row['gender'] == "Male"){


	echo $row['fullname']." ".$row['type']." ".$row['network']." on his profile";

	

	}else{

	

	echo $row['fullname']." ".$row['type']." ".$row['network']." on her profile";

	}


}

	

?>


As you can see all this is doing is checking the Update table and sorting it if they are male/female

But this will pull everything from the update table, and I need it to ONLY pull it for the users he is following.

My following table consists of 4 fields

linkto
linkfrom
fullnameto
fullnamefrom

I just don't know how to work the statements.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
First question: are you clearly capturing the information? I can't easily tell, from what you've listed. What are the table relationships involved? How do you define "Is following"?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Basically

The link to table has 4 fields, link to link from and there Full names

I need that coded to only pull the people from that table if the link from field is the name of the current user, which is the $userid variable

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You'll need to use a join.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Replys like that don't help :/

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What I mean is you'll need something like:

"SELECT * FROM updates INNER JOIN following ON (updates.??? = following.???) WHERE user = '".$userid."'" AND ???

It's hard to be more precise without understanding your database structure and usage better.

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Okay.

Ever used Facebook or Twitter?

I'm designing a piece of software that allows users to follow other users, and when the user clicks the Follow button details are entered into the database table LINKS

Which is linkto, linkfrom, fullnameto, fullnamefrom

So, if I was to follow you on the site, the following details would be entered

wingedpantha, bishox, John Smith, Bill Gates

So there we go, now I'm following the user

But now I need on the index page recent activity of everyone I'm following which is stored in a different table, this data is inserted when the user changes something on his profile.

And i need an if statement to say, when the user is following that user, pull all the data from then updates table, but I can't get it to work.

Refer back to the first post now you understand what's going on :p

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
OK, it sounds like you need a table (possibly your follow table) that either indicates when you last checked the user, or something similar. You also need to keep track of when each item being followed has been updated. Then you do a select on the two tables joined together and a where clause on the follow date less than the update date.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#9
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Hmm

I was looking at it more along the lines of

A MySQL Selection to select all the people who I am following

And then an IF statment to select them all from the other table

It just didnt work for me D:

#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
That's likely to result in a large amount of data being returned, much of which could be completely irrelevant to what you're doing.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog