Note that there are some explanatory texts on larger screens.

plurals
  1. POfetching multiple usernames from a database
    primarykey
    data
    text
    <p>I have a comments section on a website i'd like to streamline a bit if possible so it's not as much of an impact on the database. When a user selects a post, and if it has comments associated with it, it lists the comments. when the comments list, it fetches the username from another table. I store the id for the user in the comments table, and use that id to select the record from the users table. and displays as "user" said:</p> <p>lets say i have 1000 comments on a post, it will hit the users table 1000 times to grab user names. I think this is probably a bad design. i thought of a few solutions, but don't know what would be recommended in this situation. </p> <p>should i just be storing the username inside the comments table?</p> <p>should i store all of the usernames already called in a session array?</p> <p>put all of the usernames in a file, and call from the file?</p> <p>or is there another solution that i haven't thought of?</p> <p>i'm kind of confused. I thought i was doing the right thing by using the IDs in the comment table, and then using it to fetch the username, but after reading about a million posts on using less impact on the database, i'm starting to question myself. </p> <p>WOW, thanks for all of the useful answers. here is the table scheme, i don't know why i didn't put in in originally.</p> <p>comments table for jokes:</p> <pre><code>id | author_id | joke_id | date_created | body ---+-----------+---------+--------------+----- 1 | 3 | 2 | 2011-06-12 | this is a comment </code></pre> <p>and for the users:</p> <pre><code>id | user_name | password | email | date_joined | visible ---+-----------+----------+-------+-------------+--------- 3 | booboo | password | email | todays_date | 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload