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.
Related
I'm currently working on a project where people can give theire feedback about the website, just like www.usabilla.com. But i'm stuck at designing my database.
I would like to make it possible for users to create matrix radio buttons with a label above them. Something like the second image on this page; https://www.webpoll.org/program/help/Help_QuestionType_GRB.php
Does anyone of you guys have an idea how I should design my tables, including the relationship, to make this happen?
Thanks in advance.
You can create a standard Product table with id, title, description, etc...
and another table called product_ratings with a product_id relationship, user_id (User relation) and 4 more columns as Quality, Efficiency, Price, etc... every of this columns will be an integer or NULL.
Firstly, I'm quite new to PHP having only dived in some three weeks ago but loving it as a new thing to learn! I have a specific problem that I cannot seem to find a solution for via Google. I'm running a test page that will form the basis of a final product for a local recreational club that runs competitions and wants to display the results online on their website.
I've created a MySQL database and called it 'results' and imported as a CSV a sample of competition results. My code to connect to the database works as the page displays the "Database Connection Established" message.
The database contains a table called 'z_any_year_results' and the table structure looks like this:-
Record_Number Field Value
1 Field_1 Value_1
2 Field_2 Value_2
3 Field_3 Value_3
4 Field_4 Value_4
5 Field_5 Value_5
I understand how to select the specific table using
mysql_select_db("results") or die(mysql_error());
$data = mysql_query("SELECT z_any_year_results FROM results")
but I need to echo a specific field from the table in a specific section of the web page. So for example, in one section of the page I need to output the field containing the value Field_1 and nearby on the page the field containing the value Value_1. But in another section of the page I need to output the field with the value Field_4 and nearby on the page, the field containing the value Value_4. So I guess my problem is how to extract a specific piece of data from a table to the exclusion of all other records in the table and outout it as an echo on the web page. I cannot find anything on the web that is written in a simple step-by-stepway to help novices like myself understand.
Can anyone point me in the right direction on how to achieve this?
Many thanks in advance.
You are using a type of data design known as key/value design. In other words, each row has the name of a data item and its value. That's not an ideal sort of design for a beginner to use, because it makes for fairly intricate queries.
To answer your question, if you want a certain named field's value you use this query.
SELECT Value FROM z_any_year_results WHERE Name = 'Field4'
But, maybe you want a design that resembles your application's entities a little more closely.
You might have an entity, a table, called, contestant, another called contest, and another called prize.
contestant is a table with columns like contestant_id, surname, givenname, email etc
e.g. 1 , Ellison, Larry, larry#oracle.com
Then you can use queries like SELECT * FROM contest WHERE YEAR(datestart) = 2016 which will make your queries more closely reflect the logic of your application.
Not sure my title is definitive enough, but here's my dilemma.
Firstly, I have two database tables.
The first one lists all specialitities like this:
ID, Description
The second table stores a practitioner ID with a Specialititiy ID from the above table.
So I have say table 1 with 100 specialitities listed in it.
And in table 2 I have say Practitioner ID 1 with say 5 of those specialitities.
Example:
Practitoner ID, Specialitiy ID
123,31
123,45
123,67
123,68
123,81
Now, I want to edit those through a form.
I can list all the specialities through a loop through an array of all the specialitities, including a checkbox adjacent to each speciality.
But how do I check the box matching those specialitities listed for the practitioner?
I have a PHP function that gets all the specialitities from the specialitities table and I then loop through that array to list them all, with a checkbox for all of them.
I also have a PHP function that gets all the specialitity ID's for a specific practitioner.
Is there a method of matching the ID of the speciality from the practitioners table with the speciality listed on the form, and checking the box?
I'm not sure I've made myself as clear as I should here, but it might make sense!
I use MySQL and trying to write a PHP script for my school project.
There is one table named lessons contains this columns:
-id
-lessonid.
-studentid
I also have two different tables for notes and announcements
announcements and notes tables contains these columns:
-id
-lessonid
-content
-createdtime
I need to order both announcements and notes from latest to oldest by createdtime but also need to show all lessons a student takes.
For example: A students takes maths and physics lessons. I need to display him/her both notes and announcements for both of physics and maths and all items should be ordered by date. (like a timeline.) And of course I will not show him/her the notes and announcements for chemistry lesson. Also it will be good if I can say it is note or announcement on the list.
Can you help me to write SQL and PHP code for that?
Thanks.
EDIT: This is where I have stuck:
I have combined two tables and ordered them by date. But can't combine them with the lessons a student take.
SELECT title, created, lessonid FROM (SELECT title, created, lessonid FROM notes UNION SELECT title, created, lessonid FROM announcements) as a ORDER BY created DESC
First of all, thanks for letting us know that this is for a school project - therefore I won't give you the answer. If it is in the project then your teacher should have given you the concepts to come up with a solution.
Your question is well put together and I can see how to solve it but ... It's your project so you need to have a crack at it and post what you come up with.
I will give you some hints to get you started.
You need a query to combine the announcements and notes table. Then you need to group the data by the lesson and join that to the students. This is all basic SQL.
Good luck. Post what you come up with.
I'll also, follow fellow posters advice, and not do the legwork for you. but won't let you go empty handed, so will give you the concept.
there is a thing called third normal form, we decide how many tables according to that concept, so if its a big database then separate table for first name and separate for last name, as many people share those among themselves, so saves space and redundancy etc. so one table for person has personid as primary, and has lastname foreign key to refer to last name table , we generally name it lastNameRef, similarly firstNameRef. so now, each person has lot of classes, and each class has lot of persons(students) in it. so this is a many-many relation - we create a allreference table to solve this many to many problem. so there is one table for classes which has class id as primary key, so now u create a all reference table which a recordId as primarykey, (just for namesake) and personRef(refers to personId in person table) and classref(refers to classId in class table) if one person has two classes, another entry with same personId but different class Id, at the end, you can query the name of person from person table, and name of class from class table and create join on their foreign keys but use all three tables, result is (JOHN MATH, JOHN SCIENCE) etc, same way you display all notes for john searching name in person table, and subject in class table,and notes in notes table
Currently I have a form that submits an image with textfields such as
title, description and another field that autoincrements for imageID, another
area for the actual file , called vfile, and *** another part that has
3 checkboxes and a text field.
Everything works fine, and this is what it does. Submits the data to a database so that it can pull the information to a page on the website.
The only part I am trying to update is:
The 3 checkboxes and the textfield.
Lets say the first checkbox reads: Apples
The second : Oranges
The Third: Grapes
And in the other category is a blank textfield that if you add something, it would add it to a category called "Other".
So the database design has 4 fields: 1 - apples, 2 - oranges, 3 - grapes, 4 - other.
When I click a checkbox, it would add checked to the database under the correct one, either apples, oranges, or grapes.
If I add a field to the textbox such as: Bannanas, then it would add "Bannanas" to the database field vother and show that in the database.
This is all fine, but what if the next picture has all 4 items, plus another one? Such as if the next picture had Apples, Oranges, Grapes, Bannanas, and Plums?
How could I have the "Bannanas" other category, change into a checkbox category that could be chosen for the next pics when I go to the add images page next time.
So that when I go to the second picture to submit, it would give me the option of not just 3 checkboxes, but 4 checkboxes now, that I could check the first 4, "Apples, Oranges, Grapes, Bannanas" and then put Plums in the other category.
Basically upon submit it takes what is in the other feild and addes a new category to the database, which is then displayed in the array of checkbox choices and it is removed from the Other Category now, for it is a checkbox. (thus it would not want the value left in the old field, for it would keep creating the same category over and rewriting the old data possibly.
Anyway, any suggestions?
Thanks in advance.
(It sounds like this is more of a database design question and not a php question, but I may be misunderstanding what it is you are looking for advice on)
It sounds like you are saying that these attributes (Apples, Orange, etc) are stored as columns in your main table; but the situation you are describing sounds more like Tagging. Typically you would maintain a list of things that get tagged (your images), and a separate list of all possible tags (Which would be a table containing the rows : Apple, Orange, Grape). Your UI has the option to select from pre-existing tags (rows in the tag table) or add a new tag using the "Other" box. New tags would be added as a new row to the tag table. Since tags and tagged items have a many-to-many relationship you would create a third table (called a join table) that stores keys of tagged items and keys of tags; that way you can select either side of the relationship easily : get all the tags for a given item; get all the items with a given tag.
Does that help?
(EDIT : for comments)
So, Activities sounds like the list of Tags. If I want to show a form with checkboxes for all the Activities I can query the activities table for them. Each of those checkboxes can have a name attribute or something that captures the ID of the row that its bound to.
Also I would select from the join table the ids of the tags that my currently viewed image has selected. As I am populating the checkbox list I can check this result set to see if the id of the checkbox I'm putting on the page is in the list of tags for the image.
To store this back to the db on submit, the easiest thing is probably to (in a transaction) delete all the entries for the image from the join table and replace them with new entries based on the state of the check boxes in the form.
Drop the apples, oranges and grapes columns.
Create a second table with two fields: imageID and itemtype.
Don't make any of the two a key. Now you can list as many different types of items for each image as you need. It will be comparatively expensive to get the list of item types in use from the database but unless you have millions of items this shouldn't be a problem. (Mikeb is suggesting to keep the list of item types in use in a separate table to speed this up.)
The alternative is to dynamically add a column to the first table for each item type you encounter. This will create a very sparse table. I wouldn't do this.
You need to change your database schema to support an infinite number of attributes.
You should move your list of attributes from a set of fields in the record to a list of related records in a new table. This new table requires 2 columns. The first is the primary key from the existing table so you can establish the relationship between the tables. The second is the attribute field ('Bananas' or 'Apples' or 'Plums', etc.) You can have as many records in the attributes table as you like for each record in your main table. You could also have no attribute records if none are checked.
This kind of relationship between two tables is called a one-to-many relationship.