O'Reilly logo

PHP 5 Social Networking by Michael Peacock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Listing friends

So far thanks to this chapter we already have lists of users and the functionality for our users to build relationships. Now we need to combine these to build a friends list for our users. This would either be a user viewing their own friends, or viewing the friends of another user.

Our friends

To view our own friends, we would visit http://oursite/relationships. This would call our relationship controller's default method, which needs to get our friends and display them on the page.

In our model, we need a query that looks up all relationships where we are either usera or userb, and depending on which we are, looks up the details of our connection from the other user field. This is done with a simple IF statement within the query. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required