I am trying to figure out the thought process behind the following. From a list of records displayed on the screen (php/mysql, each item will have a combo box or command button to "save to favorites". I would prefer the combobox, but beggers can't be choosers. This saved to favorites is a tab that list those items from the combo box or command button.
Make a table and copy the item number into that table and under the "saved to favorites" display those records? I guess another combobox on each listing to clear it from my favorites???
Did I just answer my own question? Could it be that easy???
Possibly,
If I understand you right, you could populate an item and it's item value.
Then submit this item number and user_value from a session maybe into a row in a new table, possibly favourites?
Would that work for you?
Unique key in your DB
unique index(user, item);
Related
I have a table which can add up rows (insert row() method in js) when clicked on a button.
First column has a select tag which is populated with the product names from data base. Second column has a input text box for quantity. Next is a button. When I click on the button it should multiply the price of the selected item from first column with the quantity and set the answer to the next column i.e price.
This is working for only one row. When I add new row and click the button for setting price, it will take the value of first row itself.
This all should be done on application level on client side with proper server side checks on submission. You shouldn't need database CRUD at this point.
I have a SQL Database where the users can create a ticket then update the ticket if need be. This all works and the user can view the updated field in the , but what I would to achieve is to display the newly updated field in a different textarea field but not be able to edit it and only edit a new textarea field. Once saved and the user needs to update it again it needs to then display the 2 uneditable textfields and display new textfield to update.
Here is my code what i have at the moment:
<div class="form-group col-lg-12 col-md-12 col-sm-12 <?php echo (!empty($description_err)) ? 'has-error' : ''; ?>">
<label>Description</label>
<textarea name="descriptionfield" class="form-control" required="required" placeholder="Enter Description"><?php echo $description; ?></textarea>
</div>
So with this code I can update and delete but only displays in the same textarea.
Can someone point me in the right direction to achieve this?
Hoping what I explained makes sense.
Thanks
Something like the below image
So you are only able to update and delete a textarea but you want to show the original one and a new empty text area after they submit, then if they update that one, the original one and second one show all while allowing a new textfield to be there?
You aren't creating the text-boxes, submitting queries, and fetching results in a way the allows you to do that.
What you need to do is:
In your general application you will need 2 things, the empty text area field for the which you already have. An empty div area where you could display the old text areas.
In your database you need to add another table because you you will basically be joining these child text area updates updates. new table: textareachildren.
When somebody submits a ticket, that text area information should go into your first table where the info is going which is already happening. Now I'm assuming your table for those posts has a primary ID correct? so lets say we just put a ticket in and the ID is 1. Here is where #Padmanabhan is trying to find out, when the ticket is submitted the page is refreshed correct? and it shows that ticket they just submitted?
Now they want to edit that ticket's text area, I assume you already are pulling in the ticket by it's ID. Since you said they could already edit/update but it just shows the value they submitted. It looks by your picture that theres a note added and new note section. OK so thats good, so within that function where they could update the ticket text area field, a few important things need to happen. Once they click update, you need to run a sql query to input this new textarea value into the textareachildren table. within that table there should be 3 columns, the primary ID of the new items in there, the value of the textarea field, and third the important the connecting_ID which is the same value of the ID of the original ticket ID. this is how they will be connected and you could display those historical text areas.
Now go back to your original query that displays the ticket when they first submit, in there you need to also query by joining the the original ticket id with the connecting_ID of the new child textarea. The query will say ah yes, I am pulling this textarea value from the other table because my connecting_ID is 1 and it matches my 'parents' so I know I belong to them. Then just display that in the html within a new text area field that does not have the option to update/edit, since its probably a for loop for all those children that you want to show, you could add in the HTML textarea disabled readonly attributes, and even add classes to it so its like grayed out or something that shows you can't edit.
So to summarize every time somebody updates the text field you aren't changing that original value since you want to display that, you just add this new child textarea field value in a new table, when you query to show those old values to you just join them and display those historical textareas how ever you want.
I have a search form that the user uses to find persons from the database, the results are displayed on a table, then the user can choose persons from the results table and add them or remove them from another table (the CGridView) and this last table will be saved to the database when the user clicks save button. My problem is that I'm adding and removing the persons (the rows) with jQuery, so when I use the sort function of the CGridView, clicking any header, the rows that were added with jQuery are lost. Also, when I remove rows from the last table I want to refresh the table so the zebra style rearranges. How can I do this without losing the data added with jQuery?
I want to edit/update, multiple rows together in Yii CGridView.
Say, each row has a checkbox and a single edit/update button, I select multiple rows and by clicking on edit/update button all selected rows are opened for editing and update.
Is this possible with Yii CGridView..??
Use the selectableRows property of the CGridView.
According to Yii Documentation for CGridView
public integer $selectableRows;
the number of table body rows that can be selected. If 0, it means rows cannot be selected. If 1, only one row can be selected. If 2 or any other number, it means multiple rows can be selected. A selected row will have a CSS class named 'selected'.
You can use the the $.fn.yiiGridView.getSelection(containerID) to retrieve the key values of the selected rows.
Add some more buttons either at the top or bottom of the gridview with actions for edit, delete or whatever action you need to take and pass the key values retrieved above.
If you want to edit rows in-line you can use extension phaActiveColumn which I messed up to support multiple rows (the whole table if desired).
EDIT: well, the extension basically creates an input field replacing the grid cell when user clicks on the cell. The field will have the cell's value for starters and it then sends an ajax call to controller, as soon as the user presses enter, asking to save the value of the field, which will be the user's input.
My addition was to create one such field for every cell in the row and store user input in javascript objects which then get send all at once with one ajax call to the controller. Multiple row updates are supported (creating adequate number of javascript objetcs).
If anyone has any interest in this there it is.
phaEditColumn2
phaAbsActiveColumn2
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.