Querying info from one table based on info in another


Posted on 16th Feb 2014 07:03 pm by admin

Hi, I am currently trying to make a part for my user driven website where one user can subscribe to another and whoever they have subscribed to is echoed back on there profile page.

my users table structure is: id username password and my subscription table is: id user_id follow_id

i am currently trying to query the logged in users subscriptions with this sql_query

$subsQuery = mysql_query("SELECT U.username FROM users AS U INNER JOIN subscription AS Sub.follow_id=U.id WHERE Sub.user_id=".$ID); $ID being the logged in users id.

However when trying to echo this on the page using this bit of php:

<? while ($subs = mysql_fetch_assoc($subsQuery)) { ?><br /><br />
<? echo $subs['username'] ?>

<? } ?>

it throws back this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/avince/public_html/users/user.php on line 53

Any help would be much appreciated!

271 Like 7 Dislike
Previous php-forum Next php-forum
Other php-forum

Pspell with my own dictionary
Hello!
I've tested two cases using pspell functions.
1)
Code: $dictionary_link = pspell_new

Pre-Fill out a PHP form...??
This is for work actually (geek squad). We have to fill out this online php form at work over and ov

Output Full URL of Current Page
Let's say I am currently viewing a dynamic page:

http://www.mydomain.com/directory/index.php

Problems generating word documents on server side for security reasons
I have a problem with word documentation generation when generating a word document (docx) with PHP.

php ajax - two drop down list with a submit button
i have created a form with 2 drop-down list and a submit button. I would like to know how to pass th

Need help with a mail notify function
I was tasked with setting up a site that's been prewritten. The site is basically a form that captur

Question about the upload of large files
Hi there,

I have a question about the upload of large files, like videos (files generally abo

How to make URL loads only on login
On my page, when a user login he's redirects to user_home.php. I made it also to open the chat scree

Mysql query, two times?
Hello to all,

I'm new to php coding and i like it alot. I need help with some noob stuff.

problem with php mysql query
Hi guy's...

I'm totally lost here..because don't have any idea how to make a query for grab r

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash