close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Function for displaying data from seperate tables in same database.

Thread began 1/04/2010 7:22 am by ijk76319396 | Last modified 1/11/2010 6:44 pm by Jason Byrnes | 1042 views | 6 replies |

ijk76319396

Function for displaying data from seperate tables in same database.

I am trying to display two separate data fields from two separate tables but have them connected two each other in a repeat region. So basically I want the name of a user from table one, next to it I want the date of his last upload from table two.

So it would look like (USER 1 last uploaded on DATE)

right now I have something that looks like this for mySQL

SELECT  uploads.`date`, subscribe.`date`, subscribe.subscribe2  
FROM subscribe, uploads
WHERE subscriber = %s AND uploads.`date`= subscribe.`date` ORDER BY uploads.`date` DESC"



Am I on the right track or way off here? Why wont it work?

Sign in to reply to this post

Jason ByrnesWebAssist

Your close, but you have to join the two tables together to get the correct data.




your subscribe table should have a primary key column, the uploads tabel should have a foreign key column that is used to relate the upload top the subscriber. This foreign key column can be used to join the two tables together using an INNER JOIN:
SELECT uploads.*`, subscribe.*
FROM uploads
INNER JOIN subscribe on uploads.<primaryKey> = subscribe.<forignKey>


you will need to substitute the names of your primary and foreign key column in the example above.


See the following for more info on join queries:
sql_join.asp

Sign in to reply to this post

ijk76319396

How do I assign the foreign key to the field 'dates' in the table 'subscriber', the code I have now looks like...

SELECT uploads.*, subscribe.* 
FROM uploads
INNER JOIN subscribe on uploads.message_id = subscribe.date
WHERE subscriber =%s AND uploads.`date`= subscribe.`date`
ORDER BY uploads.`date` DESC



and is still not getting any results.

Sign in to reply to this post

ijk76319396

PLEASE DISREGARD MY LAST POST: I am trying to do it through a new method but I still can't get my results. Alright instead of trying to pull the date from a different field I have added an insert record behavior to when the user uploads his page so it enters the date into the subscribe table, it works fine, and is entered into the database, BUT, I am still having trouble getting that date to be the one that shows up next to the last uploaded page.

My database is structured as follows:
ID=Key Column
subscribe2=(the username of the one being subscribed to)
subscriber= (the username of the one subscribing)
date=(a timestamp)
SUBID=( a unique numerical ID associated with each user)

Now when someone (user1)subscribes to a user (user2) the following would be entered into the database
ID=auto
subscribe2=user2
subscriber=user1
date=current
SUBID=6(user2's unique numerical no.)

Now when user2 uploads a new page the following is entered into the same database
ID=auto
subscribe2=NA
subscriber=NA
date=current
SUBID=6(user2's unique numerical no.)

so if the two above were consecutive rows it would look like this

1 - user2 - user1 - 1/3/2010 - 6
2 - NA - NA - 1/4/2010 - 6

My RSquery looks like this

("SELECT * FROM subscribe WHERE subscriber = %s ORDER BY `date` DESC"



This gives me the results as far as the users name being subscribed to, but with the date in row 1.
How can I get the users name being subscribed to BUT with the date from row two. Being that the SUBID field would be identical I thought I could group them together somehow but I'm not sure as to the method. Thanks!

Sign in to reply to this post

Jason ByrnesWebAssist

Instead of storing NA for the usernames the second time around, store the actual user name so the second record will look like:
2 - user2 - user1 - 1/4/2010 - 6




then change the order by clause to:
ORDER BY `date` ASC


so the second record will be the first one returned.

Sign in to reply to this post

ijk76319396

That solution only partly solves the problem, I can user session variables to enter the username and unique ID, but since 'user2' is updating their page it is not possible to enter user1's name, and since user1 is the one subscribing then there is no data to filter the results using their current session variable. The record looks like


2 - user2 - NA - 1/4/2010 - 6

Is their anyway to filter it by the userID number showing the last date but only return results filtered by the current session variable of the user logged on (the subscriber) so for example... if I had user1 subscribing to user2 and these two rows exist in the table.


1. user2 - user1 - 1/3/2010 - 6
2. user2 - NA - 1/4/2010 - 6

when user1 is logged on with a session variable equaling their username I need to filter by username= user1

the results I am looking for would be , user2 1/4/2010

Sign in to reply to this post

Jason ByrnesWebAssist

the problem is the way you are creating the database, it is not going to do what you want this way.


you should have a users table
users:
userID - Primary Key
userName
etc...

an Articles table

articles:
articleID - Primary Key
articleUserID - Foreign key relation to the users.UserID- this is the ID of the author
articleUpdateDate
etc...


and a subscriptions table:
subscriptions:
subscriptionID - Primary Key
subscriptionArticleID - Foreign key to articles.articleID
subscriptionUserID - Foreign key to users.userID - Id of the subscribers


you can then create a recordset like
SELECT users.*, articles.*, subscriptions.*
FROM users
INNER JOIN articles (INNER JOIN subscriptions ON articles.articleID = subscriptions.subscriptionArticleID )
ON users.UserID = articles.articleUserID
WHERE subscriptions.subscriptionUserID = <User1 ID>
ORDER BY articles.articleUpdateDate ASC

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...