Populate event table - php

I have problem with making event table in php, i don't know even how to start, so it would be great if someone help me with this.
I have table users and cars, now i need to make table event that will follow which user is entered new car in database.
Can someone help me with making this table that will automatically populate with user_id and car_id that this entered(before user can enter data he must login, so i know which user is entering data, but i don't know how to take his id and car_id which he entered and put in other table(event_table))?
Thanks

You can store user id in PHP session when user loged in.
so when user make any update or insert in car. you can fetch user id from session and insert in event table.

Related

Insert record into mysql with different id (by user ID)

have this problem.
Have small web app. There are 10 users.
Every user has own form and he must fill it every day. Inserting into mysql works fine.
Problem is every user has his own numbering. YEAR-MONTH-CUSTOM-NUMBER
User 1: 202111121, 202111122, 202111103 etc
User 2: 202111221, 202111222, 202111203 etc
user 3: 202111321, 202111322, 202111303 etc
My question: how can I define inserting records via form for users into mysql?
For example today User1 save html form so it'll insert record into mysql with id 202111121.
Today the same user will fill form again and he must insert record with id 202111122
etc.
Thank you

Creating an Address book with different users.

I'm trying to make an Address book with different users in which they can log in with their username and password. And they can store the information like contact id, first name, last name, phone etc. I want each user to have his own address book.
Can someone please explain how I create different address book for different users.
Thanks a lot.
Create a database. take a primary id to each user or provide unique id.Then create another table fill the fields that you want(address book).Match the user who logged in and and with that another table(foreign key relationship).
When you login ..it checks with db then allows.After that you have to use insert ,update keywords for further process to put data in db.That particular unique id/primary key is used to fetch the related data(address book fields) of that user.
It is actually not a good question for StackOverflow but I will still roughly explain it to you.
You will need two different tables for this. The first one will be used for login details and the second one will record user's address book.
For example:
Table auth will have 3 columns id, username, password
Table addressBook will have contact id, first name, last name, phone etc and also have one more which will be called userID
Whenever any user eneter the data in addressBook their userID from auth table coloum id will be stored along with it. Now you can display their own data to the users.
If you have anymore question ask in comment here.

Inserting current user id into another table PHP

I am fairly new to PHP and am not sure how to do this.
I have two tables:
owner (ownerid(PK), username, password)
venue (venueid(PK), owenerid(FK), venuename, location, number)
owner stores the details of the current logged in user. Once the user is logged in they enter details into a form that gets inserted into venue table.
How do I take the ownerid of the current logged in user and insert it into ownerid (in venue table) so that at a later stage I can select all venues that a particular user has added, and only that logged in user can view them.
I am pretty new to PHP so would appreciate as much explanation / code as possible :)
Thanks!
If you have a logged in user you will be able to identify them either through a cookie or a session. If you store their ownerid in the session variable, then you will be able to access it whenever you require
$ownerid = $_SESSION['user']
You can then use that variable in association with the selected venues, and relate them together so only this user can view them when logged in, matching their ownerid

How to get particular updated of new added filed value in MYSQL CI?

I am working on the CI in this project i need to implement user activity tracking for logged in user like if any user see any records i can save that to the database and if any record is updated then i need show get only that particular updated filed value and show in the log table like this user 'xyz' has updated the phone number from '123456' to '546789'. like this if any recorded is updated, added, deleted, or viewed then i want to able to track that, i hope that make sense.
Any help is appreciated....
You can maintain a column in your table which will store the activity. when your required event is triggered.e.g.Updating Employee No. 1 to 100 will Store Activity as an Update and you can add one more column to store the ID of the updated Entry. hope this helps.

Fuelphp Profile Like logic or example

So I'm a bit lost at this part.
On my site I would like the give the ability for users to like profile pages.
So my logic is this.
I have a database table named user_likes, this contains 3 rows, id, user_id, liked_by.
The actual profile page has a like button on it with a class like.
When the user clicks on it in inserts the data in to the user likes table and changes the button text to unlike and the class to unlike too with ajax.
And this is the part where I'm stuck.
So the profile has a has many relation likes, I can count the likes received, but I'm stuck at that part how to keep the button unliked after page refresh.
Because my logic was this (but its a fail):
onclick the button, data insert with ajax, button change with ajax, grab the liked by id and if that equals to the logged in users id keep the button unliked.
But since it returns a list of array I can't do that.
So I don't want anybody to code it for me, I would just like a hint for this if its not a big request.
I saw that you posted the same question on the FuelPHP forum, so here I will try to give you another solution.
Why your relation needs "id, user_id, liked_by"? I think you can improve you database modifying a little your tabel.
Reading your question I think you have a structure like that:
// USER TABLE
id
username
... something more
If you create a table named "LIKE" you'll have this situation:
// LIKE
id
created_at
modified_at
... something more
So now you can create a many-to-many relation with a table named "users_likes" with:
// USERS_LIKES
profile_id // it wil be related to the user_id, is the user's profile being liked
liker_id // it will be the user_id of the user that likes the profile
So if you want to retrieve the number of the like you'll have all the information in the current user model or in the profile user model.

Categories