www.webdeveloper.com
Results 1 to 4 of 4

Thread: Display results depending on user

Hybrid View

  1. #1
    Join Date
    May 2014
    Posts
    2

    Display results depending on user

    Hello guys,

    I've made a webshop and been busy on quiet a lot programming now, I'm a beginner programmer and been lurking around the forum and decided to register.

    I've tried my best and I've googled around and really couldn't find it, so it seems like this is my last resort, haha.
    For the people that are going to help me, try to help me or even take the time to read this, thank you a lot, it means a lot to me.

    Currently my webshop is down for maintenance and could use your help a lot.

    Basically what I need is :

    Displaying specific results for each user, so there is a page with results, let's say results.php

    And there is a page checkout.php for example, now in the checkout page we have a referrer field.
    If i'd fill in at the referrer field PERSON A and submit the form, it saves the submitted information to the mysql database.
    And if another person did this for PERSON A and later on for PERSON B

    I want Person a to see the results only if he got referred in results.php

    Sorry for my bad explaining even made an image to get the picture.


  2. #2
    Join Date
    May 2014
    Posts
    2
    I think that I've messed up with my explaining too much non sense.

    I just basically need the code to fetch the results for the mysql database for each user specific.

  3. #3
    Join Date
    May 2014
    Posts
    3
    It sounds like what you're wanting to do is to show all people who listed a specific user as a "referer". In this situation you have what is refered to as a one-to-many relationship (1:M). To handle this scenario correctly you will want two tables, one to store user information, and one to store the key values of referrer and user. For example:


    |-------t001users-------|
    |userID(pk)
    |userName
    |password
    |email
    |country
    |street


    |-------t002referals----|
    |referalID(pk)
    |userID(fk)
    |referalID(fk)
    |timestamp

    Now with this structure you can find out how many times a specific user was refered, who refered them, the date and time when referal took place, etc.

    A quick query that would yield a list of all users who referred a specific user (what I believe you are after in your above example) would be as follows:
    Code:
    SELECT * 
    FROM t001users as t001
    JOIN t002referals as t002 ON t001.userID = t002.referalID
    WHERE t001.userName = 'tHeUsErSNAME';
    I'm not sure how large your system is but you may look at indexing the username column as well since it is being used within the WHERE clause.


    Hope this helps

  4. #4
    Join Date
    May 2014
    Posts
    3
    I duplicated column names on accident in t002referals. It should really be like this:

    |-------t002referals----|
    |refID(pk)
    |userID(fk)
    |referalID(fk)
    |timestamp


    Sorry for the confusion. I caught it after I posted, and it doesn't seem that I'm able to edit my posts :/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles