Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    23
    Rep Power
    0

    Setting a permanent $_SESSION


    I currently run queries based on the id which is set in the session, where users can see what they have inputted. However, I want to set up pages where others can view what each other have entered from specific tables. What would be the best way to do this? Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,465
    Rep Power
    594
    Probably a database.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    23
    Rep Power
    0
    Originally Posted by gw1500se
    Probably a database.
    I figured that, can you elaborate how I would set up the WHERE clause of the query. I currently have it as WHERE id = $_SESSION['id']. However that obviously changes when people log in and out. To be more clear I want to create a page where everyone can see user 1's entry.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,465
    Rep Power
    594
    Don't store the data in a session. Its not really permanent there anyway. Since you already probably have a database for authentication, expand that table to include whatever data you want to store for that particular user.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    23
    Rep Power
    0
    I have all my queries using $_SESSION, can someone help me how I would set up the variable to put in the query where anyone can view that users entries?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,465
    Rep Power
    594
    You are not making sense. Queries are for databases not sessions. I gave you a solution that is permanent.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    23
    Rep Power
    0
    As I said I have my queries by using WHERE id = $_SESSION['id']. Your solution did not make sense to me, as I do all of my queries with $_SESSION either 'id' or 'username'. If you could help me with the problem I asked about that would be great
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,465
    Rep Power
    594
    You're putting a session id in your database? How do you find records when that session goes away or is deleted?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    23
    Rep Power
    0
    each user has their own id? this is how I have seen every registration tutorial done including the one stickied on here
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,465
    Rep Power
    594
    Correct. This is the confusing part. Why are you using a session id in your query rather than the user id?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  20. #11
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Burb of Detroit, Michigan
    Posts
    88
    Rep Power
    77
    You're just doing one unnecessary step in programming, for you must be pulling the id in somewhere when a user logs in anyways. However, I guess if it ain't broke, don't fix it.
  22. #12
  23. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Well, his "session id" probably is the user ID stored in a session.

    ctudor11, forget those sessions and queries for a second and think about what you wanna do. You have users, and you have data associated with those users. What exactly does this data look like, and how do you want to show it to other users?

    As a simple example:

    Let's say I have an online game, and I want a highscore list showing the best players and the points they've achieved. To do that, I simply track the result of each game in a table called "achievements" or something:

    Code:
    user_id | game_started    | game_finished   | points
    --------+-----------------+-----------------+-------
    14      | 2013-3-30 23:48 | 2013-3-31 00:15 | 2914
    15      | 2013-3-31 01:17 | 2013-3-31 02:05 | 8805
    21      | 2013-3-31 05:19 | 2013-3-31 05:43 | 2301
    Now I can display a global highscore list and also personal highscores by specifying particular user IDs. Something like
    Code:
    http://mysite.com/highscore.php?user_id=21
    And then I look up the results for this user.

    Comments on this post

    • gw1500se agrees : We need to understand what the OP is really trying to accomplish.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    23
    Rep Power
    0
    thank you jacques you always give good advice, how would I go about setting something like this up
  26. #14
  27. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Actually, I was hoping for you to tell us what you wanna do.

    We can't help you implementing something if we don't even know what exactly that is. What data can other users see? How do they see it? Do they click on a user profile? Do you have a big list showing the data for all users?

    It would also be helpful to see the current database tables and queries you're using.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    23
    Rep Power
    0
    Sure, thanks for your help, I really appreciate it. So I have contests where users select the winner of each sports game that week, in this case nfl. The table looks like

    id question_id user_id username prediction correct

    1 1 2 user patriots 1

    The correct column begins at 0 but if it equals the value in my answers table then changes to 1. So I have a quiz leaders page, where I rank the players based on number correct.

    The query is use for that is

    PHP Code:
    $query "SELECT username, COUNT(`prediction`)
     FROM contest1_predictions WHERE correct = '1' 
     GROUP BY username ORDER BY COUNT(`prediction`)
     DESC LIMIT 0,10"


    So that lists the top 10 players, I want each username to be clickable, showing the picks that that particular user submitted, please let me know if that helps.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo