How to query a table whose name is dependable on the id? - sql

I am making a website like Facebook. Whenever the user signup, a table named his/her 'id' is created in every database like messages, friends etc. My question is how to query that table.
This is what I tried so far:-
$id=$_SESSION['id'];
$id1=(string)$id;
$result=mysqli_query($conn2,"SELECT * from '$id1'");
while($row=mysqli_fetch_assoc($result))
{
echo $row['frnd_id'];
}
But I am getting an error.

Related

Insert to certain row in sqlflite

I am attempting to make a database that stores user information on the device. I am using flutter combined with sqlflite. I want to always store the data of the current user in row one of the SQL database. Is there anyway to do that with the .insert method?
int id = await db.insert(
'user',
user.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
This is the code I am using for inserting, but when the user changes the screen name or email, it will put the user now into the second row.
After a long period of research, I came to discover that the issue was not in my SQL code, it was instead in my use of the code. The object was returning a list of all objects and I was thinking it was returning one object.

Laravel get a random user with where clause

My table schema is a id field, name field and a friends id field.
Every user must have a maximum of 2 friends. When a new user is created and event is fired and a listener which listens to the created user event then adds a random friend to a newly created user.
$randomfriend = DB::table('users')->select('id')
->groupBy('friends_id')
->havingRAW('COUNT(*) < 2')
->inRandomOrder()->first();
it still returns users with maximum number of friends. Can someone help me with this?
first of all create another table for friends relations.
for selecting a random user this post can help you:
enter link description here
don't forget to put this code in while loop for checks.

Defining Logged in Users Details in Oracle

I dont know how to go about defining a set of attributes to a user when they have logged in to Apex. After logging in with their username and password, the tables should display data about that User. The username and password are stored in a table with general details such as 'name','email address','home address etc' with 'Employee_id' being the primary key. When they have logged in they should have that specific row's data values. What I have tried to attempt:
I made a report want to specify the name display:
SELECT NAME
FROM EMPLOYEES
WHERE EMPLOYEE_USERNAME= :APP_USER
(Have tried to get the current logged in username).
This has not worked and nothing is displayed.
For your above query to return data the value of EMPLOYEE_USERNAME must match the current username which is stored in the :APP_USER variable. Please note that :APP_USER retrieves the username of the current user in uppercase. I suggest you change your query like this:
SELECT NAME
FROM EMPLOYEES
WHERE UPPER(EMPLOYEE_USERNAME)= :APP_USER
This type of query has some performance problems i suggest adding a trigger that will ensure the EMPLOYEE_USERNAME is in a uppercase or add a Function Based Index on UPPER(EMPLOYEE_USERNAME).

Getting user profile data in Silverlight 4

I am fairly new to Silverlight and RIA services, and I am trying to build a small project to understand it. So basically I created a Business Application, and I have the normal Login screen where I can add a user. That is fine and I can add a user and get him into the aspnet_Users table. Now I have created some extra fields, like Mob No, Tel No, DOB, Locality etc, which I have put in a table I have created called the UserProfile, and my idea is to get the username that was registered, and insert it into my UserProfile table with the other relevant data.
So I created a page called Profile.xaml, I created a UserProfileDomainService.cs where I have just one query, to get the user profile data from the table, and then created a Details DataGrid on my page, and the QueryName in my case is GetUserProfilesQuery(). Now what i wish to do is, get the user logged in, get his username, and check in my table to see if there is already data in the table. If there is populate the fields on the DataGrid with data, so that the user can modify this data, and if not, allow the user to insert data into the table.
So I have created a UserProfileViewModel class, and I want to create the query to get the data relevant to this user. However I got stuck on how to do all this, and how to get the user logged in.
Can anybody give me some advice or point me to some tutorials on how I can achieve this?
Thanks a lot and your help is very much appreciated.
In your domain service query you can use ServiceContext.User.Identity.Name to get the information specific to that user to include in your db query. I do something similar in our project.
We use entity framework so the LINQ to Entities query looks like:
return this.ObjectContext.UserSnapins
.Include("Snapin.EvolutionModule")
.Where(si => si.User.UserName == ServiceContext.User.Identity.Name)
.OrderBy(si => si.PageOrder);

MySQL joins for friend feed

I'm currently logging all actions of users and want to display their actions for the people following them to see - kind of like Facebook does it for friends.
I'm logging all these actions in a table with the following structure:
id - PK
userid - id of the user whose action gets logged
actiondate - when the action happened
actiontypeid - id of the type of action (actiontypes stored in a different table - i.e. following other users, writing on people's profiles, creating new content, commenting on existing content, etc.)
objectid - id of the object they just created (i.e. comment id)
onobjectid - id of the object they did the action to (i.e. id of the content that they commented on)
Now the problem is there are several types of actions that get logged (actiontypeid).
What would be the best way of retrieving the data to display to the user?
The easiest way out would be gabbing the people the user follows dataset and then just go from there and grab all other info from the other tables (i.e. the names of the users the people you're following just started following, names of the user profiles they wrote on, etc.). This however would create a a huge amount of small queries and trips to the database in a while loop. Not a good idea.
I could use joins to retrieve everything in one massive data set, but how would I know where to grab the data from in just one query? - there's different types of actions that require me to look into several different tables to retrieve data, based on the actiontypeid...
i.e. To get User X is now following User Y I'd have to get my data (User Y's username) from the followers table, whereas User X commented on content Y would need me to look in the content table to get the content's title and URL.
Any tips are welcome, thanks!
Consider creating several views for different actiontypeids. Union them to have one full history.