Is it possible to get the values from a database-table column displayed?
For example as a html form table? or clickable button?
I have a table with values like lessonid, studentid, answer and corrected by student.
Now I can save different answer to the database, Show the selected lessons from the table.
But I want to "pick" one of them an "correct" it and save the selected answer to table.
What is the best way to solve this? Very grateful if someone have time to help me a bit.
Is it possible to get the values from a databasetable collumn shown for example as a html form table?
If you can't use an existing framework, the best way to do this is probably the use of a foreach loop.
echo "<table><tr><th>Table Headers :)</th></tr>";
foreach ($lesson as $unit) {
echo "<tr><td>".$unit['question']."</td></tr>";
}
echo "</table>";
Obviously, you could add many more columns in the same fashion.
But i want to "pick" one of them an "correct" it and save answer to table.
Not sure I understand the question, but you could potentially have a dropdown box in a form at the bottom of the page that lists the answers. You could select the "correct" one and click the submit button, which would post the data and write it to MySQL.
echo "<form action='' method='POST'>
<input type='hidden' name='action' value='answer'>
<select>
<option value='".$yourValueHere."'>".$yourLabelHere."</option>
...
</select></form>";
You could then have a section of the script that only executes when action == "answer". The section could write the selected answer to the MySQL database.
Related
I have a php/mysql application in which I have a database broadly having the following fields:
Employee No.
Employee Name
Year of Joining
Location
Job Profile
I am able to display the records using the SELECT statement with no problem.
Now, I want to be able to do the following and this is where I need your help/suggestion on how to achieve it:
Select a few records randomly (using a checkbox or any other method suggested here) from the list of records displayed.
Have a button saying "Processed" on the screen. When I click on the button, the screen should refresh and the records selected in Step 1 above should be moved to another database and only the unchecked records should now be displayed.
Please let me know your suggestion on how to do the above.
Thanks
TS
For this you can use the id of the record, to get the information of the particular record using another single select query, and also can update the record with the id of the record. (create an edit link and pass the id, on edit page get the information with the id and save it.)
<?php //your db connection and select query here ?>
<form action="process.php" method="post" enctype="multipart/form-data">
<?php
// loop starts here
echo "<input type='checkbox' name='ids[]' value='".$row["id"]."' />";
// loop ends here
?>
<input type="submit" name="process" value="Processed"/>
</form>
This will create the checkboxes and on the process.php page
you can get the ids your need to process and can move your data
to other table/db where you want and after than redirect back to
to the page where your code is.
Okay I am having all kinds of problems trying to figure the way to script this.
What I want to do is have a list of people displayed from a mysql database.
Once list is generated I would like to have a checkbox next to each person.
Now here is the tricky part (at least for me), for each person checked I would like to enter it into only 1 column in another table in the database. We will call it "rsvp" I for the life of me cannot figure this out.
Basically I would need to enter user id's from the checkbox ex these are id's checked "1,4,5,6,8". Now I would need to enter that into a database table "rsvp" and then be able to go back and modify that same entry with the checkboxes already selected.
I think I am way over thinking this and it is actually a very simple solution.
You should
1) Get the result set from the database
2) Get an array of selected members
3) Iterate of the actual dataset and keep generating check boxes, if id matches the selected id, generate the check box as checked.
4) On submitting the form, clear old entries and re-insert whatsoever has been selected.
<form>
<?php
$resultSet = getAllTheUsers here ////
$arrayOfSelectedUsers= getAlreadySelectedUsers();
// keep the array as "id"=>'User name'
while(result is not empty){
if(array_key_exists('bar', $foo))
echo "<checkbox value=$result['userId'] checked='checked' name='rsvp' />";
else
echo "<checkbox value=$result['userId'] name='rsvp' />";
}
?>
<input type='submit' />
</form>
This should give you an idea. Once the form is submitted, get all the values, delete the existing entries from the database and re-insert what so ever has been selected again.
I have a form page where users enter some data and upon hitting 'submit' a query is executed in our database that pulls up relevant information.
So, users put in two things into the form: class name and time.
after that, our php file pulls up a table with section information.
for example: ENG 212 has two sections: ENG212-001 and ENG212-101. So, in the table, it has information about the section like max enrollment and location, etc. it also shows how many people are currently enrolled in that section.
Now I want users to select a section. if the max enrollment is 10 and currently enrolled are 10 students, then the user can't select that. if currently enrolled is < max enrollment, then the user can select that section.
so, HTML page with form --> php file that pulls up the table ---> now i need a way for user to select one of the sections, but if they are full I want them not to be able to even select it.
I'm thinking of doing radio buttons but I have no idea how I'd implement them for this particular scenario
how do i implement this? i've tried looking online and I have no idea how to implement this.
any help would be appreciated.
After you submit the HTML Form and you get the max enrollment value check it in PHP and print the radio buttons from within PHP based on the value you got.
if ($max_of_section_1>10)
echo "<input type='radio' disabled='disabled' value='Section01'/>Section 01";
else
echo "<input type='radio' value='Section01'/>Section 01";
if ($max_of_section_2>10)
echo "<input type='radio' disabled='disabled' value='Section02'/>Section 02";
else
echo "<input type='radio' value='Section02'/>Section 02";
A simple if statement to evaluate if the class is full or not would do the trick.
if($row['status'] == '1') {
//Display code here
} else {
//Display class is full message here
}
If you are just trying to not allow an end user to select an input, try the html disabled attribute. if you determine a section to be full set your input method as disabled. you will still need a logical barrier in your back end too.
I want to make a form in php where there will be two categories. One for the Student profile details and another for the student's
marks details. Now the main problem is all this will be in one single form means in one page and the categories like student details will be save in student detail table of the database and the marks will be save in another database called marks database. I also need CRUD for these two categories.So how to do that?
Any suggestion and help will be highly appreciable.
Well there is no direct link between a form and a database table, so what is your problem?
Why don't you do the mysql_query() on each table one after another when you handle the form post?
You can build your form like this in order to separate the tables:
<input type="text" name="data[student][name]" />
<input type="text" name="data[category][name]" />
you PHP script then goes through the data and save it in the corresponding tables:
foreach($_POST['data'] as $table=>$row){
// do your insert statemnet here (don't foregt to escape the Parameters!)
}
I know this is a similar question to one already asked, but I was hoping for a different answers to a problem. I have a form where you can upload new articles to a database all fine works ace, wonderful, brill. The form uses a drop down menu for the type of article, I have news, gossip, travel, performances and others in my drop down box. When you upload to the db it's only going to add the selected item let's say, in this case, News.
I need the user to be able edit their articles, so I need to populate the drop down box with the selected item. I think it's a bit of a pain in the BUM to set up a database table with each of the drop items and an ID for them. Is there away of setting the selected item as value in the db, and then just using a if statement or something to populate the rest of the drop down box?
Hope that makes sense. I also thought use of a radio buttons could be a solution however I cant get that to set the selected button with the value in the db.
You could do something like this:
// array of available options
$available = array('news'=>'News', 'gosip'=>'Gosip', 'travel'=>'Travel', 'performances'=>'Performance');
// selected option value
$selected = 'news';
echo '<select name="article-type">';
foreach ($available as $val => $label) {
echo '<option value="'.htmlspecialchars($val).'"';
if ($val == $selected) {
echo ' selected="selected"';
}
echo '>'.htmlspecialchars($label).'</option>';
}
echo '</select>';
Sounds like you want to put the article types in a table or something along those lines.
Then you can load the drop-down from the table, and just store a reference to the article type ID in the article table.
On the plus it should make retrieving all articles of a given type quite a bit faster as you'd be doing the lookup on ID.
It sounds to me like this is more a database design issue than anything else. Your basic design seems flawed. I'm trying to deduce the issue from your question so bear with me if I'm way off track.
Here is a relevant portion of the design, as it should be, IMO:
Table: Articles
ArticleID
ArticleContent
ArticleSubject (FK from Subjects)
..
..
.. Other columns.
Table: Subjects
SubjectID
SubjectDescription
..
..
.. Other columns.
Note that I called the second table Subjects to better illustrate my implication. This way, each Article has a reference to an article type (subject). Now when you retrieve data for the "Article types" dropdownlist, you would simply retrieve all the rows in the second table, and then would set the selected item based on the current selection (from the first table.)
$options = array(,);
$selection = filter_input(INPUT_POST, 'what');
$blah = true; //i don't know what to name this.
foreach($options as $option) {
echo '....';
if(isset($blah) && $option === $selection) {
echo 'selected="selected"';
unset($blah);
}
}
This is probably the fastest way. Also if you're going for speed make sure to take advantage of echo's multiple parameters.