PHP/MySQL cell showing info from another recordset - php

I am creating a PHP/MySQL web site. On one page there is a table which is showing a recordset of users (Recordset1). One of the users field is company (idempresa), where I am storing the id field from the table companies. The table shows the user fields: username, email, company. As you may guess, the cell for the company value shows the company value (idempresa) and not the company name which is part of Recordset2. This the code for the cell:
<?php echo $row_Recordset1['idempresa']; ?>
How could I update the cell content to show the company name?

Best place would be in your query as a Left Join. Then you will have both record sets in one. Here is a link to an example: w3schools.com/sql/sql_join_left.asp

Related

Is creating a new table each time a user logs in a bad practice?

I am developing an online inventory management system. I have one table for the main inventory which consists of the product names, quantity and barcodes etc. I want users to log into the system each morning and log the quantity of each item they take. I then want to store this information for the admin to view. I have developed the system so that a new table gets created each morning based on the users name and date. This is allows the user to input the quantity for each product, i then subtract that column from the main inventory table when the user clicks submit. I want to know if this is a bad practice, is it necessary to create a new table each morning? If not what method should i use?
I think you should maintain a single table for inventory, and then after a create a temporary table to store the list of items the user takes which will contain the user id, inventory id, qty etc, and then update the quantity of inventory in inventory table, whenever user picks the inventory.
In short you should create a single table to store the information of inventory which user takes instead of creating a new table each day.
Insert and fetch data according to date + user.
I wonder if you are creating new table everyday, you should not create new table in any case. In the rarest scenario even if your columns are dynamic then create a table with rows representing as column and use pivot to fetch the record. For your use case you just need to have a table which stores a new record and subtract the count from main table.

Get user information from different database

I have a big problem I have a main master database which stores the admins information like name, no. etc and also a database name .I am liking a new database with every admin and in that database the admin's private data will be saved...like one admin whose name is Jack, his data will be stored in master database now he is linked with new database name'jack' in jack database jacks all private tables and his employee details and so on will be saved ...
now when an employee will log in with mobile no. and password how can I search this because there will be thousand of admin and they are linked with thousand of database in which there will lots of employee associated with them. What is the best technique to search the specific employee with just mobile and password. I was trying that anyhow if I know the admin name then easily i go to his database and fetch his employee details and log in that employee please help me guyz i am working in php and my sql
if you know the admin details you need to use in search box with ajax operation through ajax you need to send the particular employee information i.e., enter into the employee name send ajax through the page ,and getting the employee you need to write a query then you will get particular employee name details. the query is like this .
query is:select(*)from tablename->where('tableusername',fetchusername($username))->get();

Changing the database value based on dropdown list (PHP, MYSQLi)

Since I am new to an advanced side of PHP, I would like to know how to change the database value by using a dropdown option list.
Users view of the page: This is what the user will see on the webpage. The users should be able to assign the sensors by selecting the sensors with the checkbox and using the drop down list to assign the sensor to a particular school.
SenSG Table: This is the table, Sensg, where all the sensors' information are stored. The school_id is the value which I would want to change when the users checkbox a sensor and choose a school in the dropdown.
School Table: This is the table, School, where all the schools with their respective school_id. The school_id is not auto-incremented.
How do I go about in changing the school_id of SenSG table when I assign a particular or more sensors to a respective school using a dropdown list and it will change its value based on the dropdown list.
For example,
If I check-boxed the first sensor and choose the dropdown box of option 'Republic Poly', the school_id in the SenSG table should change according to the dropdown value.
How do I go about doing this in PHP as I am completely lost.
Thank you.

Get dropdown name instead of value when editing user

I am in need of some help, I have a table where it shows the people that have signed into a patient program.
Here is how it looks:
Right now if you look in the Location column, it says 8 instead of the last option in the dropdown being Manalapan.
Here is how the database table looks for offices location:
I would like to grab the office_name data from the database while retrieving the patient information in the table,from the table patients:
It is stored in the database as pat_loc and this one is 8.
In the end, I want it to say the name of the office, not the number it is stored at, first getting it from the patient table then going to the office table for the name.
Is there such a thing that can be done?
If needed, I will show my current code to see where it needs to be added.
You could try doing an inner join so you can grab all the data you need from both tables
SELECT * FROM patients INNER JOIN offices ON office_id = pat_loc
And then accessing it through your row array like $row['office_name]

Theoretical: about php, mysql, comma separated values

I have a database with employees. the columns are first name, last name, department, internal number etc..
As for today it is a database only for one organization but in future i want to add to this database employees from other relative organizations.
What is the right way to do it:
To add another field to the first table ?
To create another table with 3 fields: id, organization_name, employees ( where in this filed i would put comma separated values of id from first table) ?
if the second answer will be chosen what will happened when an update query will be executed simultaneously from different accounts to the same organization. For example: i will be adding a user with id 55 to organization 'Police' and at the same time another administrator will be adding to the same organization a user with id 65..
In this case is there a possibility of error or data-loss ???
If someone had this kind of problem before, i really would like to read about it..
Thank You..
If the organization is only a number to group the users, then I would suggest to put them into the employees table. However if you have more information about the organization (e.g. name, address .. ) then make a new table for the organization and save the primary key of the corresponding organization in the employees-table.

Categories