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]
Related
i am using moset tree, i am creating search functionality in which
when user enters keyword such as college, then it should search in database with a value of college in tags column. if college matches then that entry should be displayed in result.
My Database View:
First Table: mt_links in which all the listing is saved.
Second Table: mt_cfvalues in which tags were saved and they were normalized
means in first and second table link_id is same. so we need to make relation with this column.
I created this query:
SELECT * FROM #__mt_links link INNER JOIN #__mt_cfvalues val
ON link.link_id = val.link_id AND val.value LIKE '%$keywords%'"
but in this way i am not getting all the results.
Tags Example: in mt_cfvalues table there is one column name as value which are keywords on the basis of which in need to get listing.
Example 1: college, university, institute
Example 2: repair, computer, laptop
if i enter any of keyword mentiond above eg: laptop which is third in listing then even i need to show that relative listing. means product in which laptop tags is used that product should be displayed as a result.
I hope i give clear information. please Help
Thanks
SELECT
*
FROM
#__mt_links link
INNER JOIN #__mt_cfvalues val ON (
link.link_id = val.link_id
)
WHERE
FIND_IN_SET(val.value,'$keywords') != 0
$keywords needs to look like : keyword1,keyword2,keyword3....,keywordN
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
I have 3 table which have relation with each others... In 1st table, i have student details contains studentid (PK), studentname, dob, etc...
Table 2 contain course consist of coursecodeid(PK), studentid(FK), coursename, teachername and etc..
Table 3 contain grade consist of studentid(fk), courseid(fk), id(pk_autoincrement) and grade.
When system starts, studentid will be load into a dropmenu. Onchange this dropmenu, second dropmenu will be shown and load with courseid take by selected student (based on studentid)
When user select courseid onchange a label will be visible to show student grade.
Everything done in 1 page... Anybody can give me sample code either in php or javascript since i am using php and mysql database.
Ajax. That is the way to go. Check here for ideas, this is doing something similar to what you are trying to achieve. Check this for more abstract code reference. This is a possible duplicate. And generally, searching for loading combobox based on other combobox jquery will give you pretty decent results.
Im trying to create a checklist system eg. a list of items to collect. the user will be able to add the list to their profile and then as they collect the items then can check the box for an item in the list click submit and the checked item will now be marked as collected. I have it coded and working fine but it makes an insane amount of queries to the database to work.
i have 5 tables. a users table (for the registered users username, id..etc), a lists table (containing the list name, description, id ), a list items table (containing the individual items. id, title and listID (to reference the list it belongs to)). userslist table (for the lists the user has added to their profile. userID and listID) and collecteditems table (this has the list items that a person has checked the box for as collected. listItemsID, UserID)
the problem is when i view the mylists.php page it will query the userslist table and return all the ID's for the lists the user has added. then once i have the ID for the list it then queries the list table to find out what the name of the list is (this could mean having to make 10 queries to the list table if i have 10 different lists added). if i added a listname column to the userslist table i would only need to make 1 query for the page and that is to the userslists table and i could construct the page with that 1 query.
First, I wouldn't worry about queries on primary keys. All your tables have a primary key referenced by other tables. These will use joins.
Second, you don't have to get the list names separately. Use a query such as:
select l.listName
from UserLists ul join
Lists l
on ul.listId = l.listId
where userId = $userid
This will return all the names in a single query.
It sounds like you should keep your data normalized (that is, avoid the redundant data) and instead gather all the data you want in a single query, by using a JOIN.
I have a select statement showing the following results:
On_loan barcode
Y 12345
Y 12345
N 12345
N 12344
Y 12344
Each barcode for a book can have more than one copy. Users can place a book on hold. E.g user '1' has reserved book 12345 and 12344. The above results show: that the two books with barcode 12344- one is available, the other is unavailable. I want to be able to show two regions in PHP, the top showing books that are ready to take out(that were on hold) and the other showing books that are unavailable which have been placed on hold. From my select query i now want my select to check to see for each barcode 12345 and 12344 whether a book has been returned. If it has i will then use the hold_date to see if its the earliest Hold for the specific book.
I understand on_loan informs me whether a book has been returned, however how can i use 'N' from on_loan for each book. I believe distinct will not work.
How can i go about doing this.
My Hold table
has the following fields:
user
isbn
hold_date
I think you are asking for a way to check if a recently returned book is on hold for another customer, correct?
The book should actually have a unique barcode per each physical copy of a book in the library, as well as an ISBN for the book in general.
Holds would be placed by ISBN.
When a book is checked in, enter that copies barcode, then pull its ISBN number and see if another customer is waiting for it.
If so, set the status for that copy to 'hold', create a related library book to hold record relation.
Otherwise, set the book status to checked in.
Assuming there is a table 'copy' that has a record for each physical copy with unique barcode and relates to a table called 'book'
that has info about a book like ISBN and Author etc, and a table called 'hold' that has the hold info an ISBN (or better, book.id)
Here are the all the copies that are checked in and have a hold on them.
select * from copy left join book on book.id = copy.book_id where copy.status_id = get_book_status('in') and book.isbn in (select isbn from hold);
Maybe you should have a bookTitle table with ID, Barcode, link to barcode tables and then you could do a query to return all copies of a bookTitle and use queries to return barcodes that are on loan and not.
The ID makes it unique.
That's not quite a good database design, if you are asking this kind of questions.
First of all, you should transform this to the third normal form databse.
Then it will look like three tables: books (name, barcode, available_count), users(user_id, name) and a relationship table users_to_books(user_id, book_barcode, state), where state can be an menu with values "on hold" and "on hands".
After that you can do all kind of stuff with counting and checking.