Quality questionnaire php mysql graphipcs - php

i'm making a questionnaire about a service quality, its contains the options (poor, regular, good, very good). It's contains 6 questions (radio button) and a suggestion box (textbox).
In the table of the database i created 6 rows for questions, 1 for suggestion and 1 for date (a friend of mine tole me to use this but i didn't get why).
q1) I'm going to atribute a value form 1 to 4 to the radio buttons options, and i'd like to sum every answer for each question, and then divide by the numbers of user that answered that question and give the mean. how am i supposed to to that? I'd also like generate reports of the month, of the year.
q2) not only about the questionnaire but for registration too. I need all the fields to be completed, no blank options, if he don't complete all of fields it'll not be submitted and there will be a warning message to the user.
q3) about the field type, i'd like it to be the same class that is in the database, i'm having a "problem". Ex: Name(varchar) : 1234(int), in the field 'name' of the table of the database 1234 will be shown as name, and i don't want this, i want only the type that i declared in the construction of the table.
q4) i'd also like to know if it's possible to create pizza graphics, about the percentage of each question, is this possible?
q5) I'm using phpmyadmin and some of my id's are auto_increment, but 'cause of my tests they at a high number, i'd like to restart to 0 the ids number, is this possible?
Thanks for the attention.

To me this sounds like what you more need is a complete surveying package. This has been done before and there are many great paid and free options.
If you are attached to a php/mysql answer, a quick search finds this as a nice open source option.
http://www.limesurvey.org/

Related

Rating system Laravel

IMPORTANT: I'm not asking for the source code to do this, I'm just looking for someone to tell me how to do it and then I'll try by myself to do this.
Hello, I'm a Laravel beginner so I'm sorry if this sound logic to you, here is my question: I need to display review on the profile of my community, I need :
Short text for the review
Rating system between 0 and 5 (star rating)
Date of the review (Month and year)
First name and last name of the reviewer
Count the number of review for a profile
I'm absolutely not looking for the source code to do this, I'm just looking for someone to tell me like 'you have to create a database, put this data in.. etc' etc because I have absolutely no idea where to start to do this.
Once this will be done, I need to display each review of the right profile and make an average of the rating which is from 0 to 5
Thank you and have a nice day/night ! :)
Well you probably will be using a database for convienence. But other methods are available too. What I would do? This is just a single example. This could not suite your environment. This is very global too as your question is.
Create a table called Review
Make some columns: id | rating | text
Create some tables with relationships to the review table
Get some stars input fields in your form
Make some post / get requests

Codeigniter - HAVING and LIKE

Related question
I have a very similar query to this question below:
Search GROUP_CONCAT using LIKE
I think my question is pretty much identical, but in CodeIgniter. Therefore I think I am just looking for the same answer but converted into active record language...
My question
To provide some background, in my case I have a many to many relationship so with three tables:
companies which has two fields (company_id and company_name)
sectors which has two fields (sector_id and text)
companies_sectors which has two fields (company_id and sector_id)
(One company can operate in multiple sectors, multiple companies operate in the same sector.)
I have grouped by company to show sectors.sector_name as a group_concat field and I have given an alias to this concatenated field at the select level:
$this->db->select('sectors.sector_id, GROUP_CONCAT(DISTINCT sectors.text SEPARATOR "; ") as sector_text', false);
I want to include a filter which selects where 'sector_text' (the group_concat field) includes the text from the query form. I understand that, because I want to run the filter on an aggregated list, I should use "having" and not "where". Per the answer to the link above, it looks like MySQL has a HAVING LIKE, but I was struggling to replicate this under CodeIgniter's active record (in fact my understanding is that CodeIgniter's ->like() is a WHERE x LIKE y which is not what I am looking for...)
At the moment I am only using a LIKE:
$this->db->like('sectors.text', $this->input->post('sector_text') );
But this filters before the grouping, which means the output will only show the sector that was searched for. For example, if Company A operates in "fishing" and "shipping" while Company B operates only in "fishing", and a user searched for "fishing", I want the result to show:
Company A - Fishing; Shipping
Company B - Fishing
(This is the desired result!)
But at the moment I am only getting:
Company A - Fishing
Company B - Fishing
... which I think is because I have used like, which filers pre-grouping?
Can someone please assist? Many thanks in advance!
PS If I can also use the alias "sector_text" instead of sector.text that would be ideal (I think I have read that "Having" allows you to use the alias?)
I found the answer! I just modified the "LIKE" to:
$sector_text = $this->input->post('sector_text');
$this->db->having("sector_text LIKE '%$sector_text%' ");
It feels a little off doing it via active record, but it works. If there is a solution that keeps it within active record then please let me know as I would probably prefer this!
Many thanks!

PHP echoing a specific field from a table in MySQL

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.

Generic structuration of a web form and a MySQL's table for saving a array of undefined length

In a web form i will ask the user for their job experiences, this data will have no fixed lenght. I need to let the user insert all the items he needs, every item will content 3 fields; job title, description and year.
My firts problem is, how can i ask in the html form for the items? i mean, whats the best way to ask items with no fixed lenght using html/php (and maybe ajax)? I saw some sites that have a button (add one) when you hit it a new item slot is showed, but i have no idea of how to implement this, an example will be sufficient.
The second part is, how can i managed the data flow in post or get?, until now, i only use fixed fields, so i always know in my php script how many post or get vars i will get. How can i use multiple POST vars without knowing the amount of them?
And the last one (and the more important), how will be the best structure for my table in MySQL? If i get multiple items for a fixed table where i will have all my users, how can i resolve the multiple items issue? For example, if my table is:
User | password | job_experiences
admin | root | (this is just a cell, how can i save multiple items here?)
jonh | 1234 | (this is just a cell, how can i save multiple items here?)
Thanks for any help!!!!
Those are 3 questions, and it's best to post 3 questions, instead of discussing all of them. I will post the basics, and if you have specific questions, ask.
First, use button to add, and a JavaScript to clone an existing row (which can have more then one input field). For fieldnames use something like company_name[] - the [] is the important part, at this will send the field as an array. If you are editting profile, you can use company_name[$id] to preserve the mapping.
Second, in PHP you will receive this as $_POST['company_name'] which will be numeric array with all the company names. Or if you specify $id - with the corresponding keys. So, you have to loop trough all company_names, if there are other fields - you retrieve them the same way, using the current key. Example:
for (i =0; i<$_POST['comany_name'].length;i++) {
$company = $_POST['comany_name'][$i];
$start_year = $_POST['from'][$i];
...
}
Next, you need 1 table for the users (username, password), and another for job experiences (userid, company, description, from, to). This is called 1:M relation

Store dynamic form fields in database

I have read other answers on this (or at least near to this) subject but I couldn't get a clear view of it so I'm asking for help again.
I have a complex dynamic HTML form that I would like to submit to database using PHP. The form is split into multiple tabs and in each tab I got checkboxes that trigger other parts of the form. Example: at a point in my form I got a checkbox group that has options of: "hotel" and "restaurant". If I check hotels, I get another part of the form displayed, specific for "hotels". Same thing for "restaurant". So it's very dynamic here and I don't know which would be the best approach for storing every form field in database. Because it could contain 15 fields or 20, depending on the selection. Any example would be appreciated as I'm not that advanced with database design.
Thank you!
So it's very dynamic here and I don't
know which would be the best approach
for storing every form field in
database.
I apologise if I have misunderstood you here but I believe that you should design the database according to the data and not the form. It is difficult to comment without knowing the exact details of your situation so here is an example:
If you usually dump all the data from a form into a single table, but because sometimes this will involve submitting 5 values and other times this will involve submitting 10 and so you are unsure how many columns your table should have, then I think the problem is in the database design.
Work out what pieces of data are dependent on other pieces of data. For example, you mention checking "hotel" might open up more fields specific to that choice. Let's assume this involves things like "en-suite", "bed type" etc. Then you should have 3 tables, a registration table (assuming the user is using the form to buy these services), a hotel table and a registration_hotel table. The registration table will record a number of details specific to the registration only such as the customer's name and a unique id number. The hotel table will hold information specific to the hotel only, such as how many rooms have en-suite. The registration_hotel table will hold details specific to that registration at that hotel. You might want a column of type bool to record whether the user requested "en-suite".
When submitting the form, check which pieces the user entered with if(isset($_POST['hotel']) && !empty($_POST['hotel'])). Then only send stuff to the registration_hotel table if that condition is true.
If this design results in making too many separate calls to the database, you might want to look into transactions which will help you to manage the speed and security of these calls.
If you can post in a specific example of something you don't know how to do, that would be useful.
You didn't specify how you can manage this dynamic form. Can you edit it's PHP/HTML source? One great thing would be if you can label your different variables like hotel[], restaurant[], etc.
If your submitted form is clear enough (i mean semantically correctly structured) you can store the whole submitted form serialized.
Note: this method only working when you don't need to search for specific items in your database.
Edit: maybe i'm misunderstood your problem.
You can create a 'metadata' table like this:
form_id | option_name | option_value
---------------------------------------
1 | hotel | true
1 | restaurant | false

Categories