So there is one specific DataTable I am working with which handles large amounts of data, so all the logic is in the PHP code at the back end. When sorting is toggled at the table, it sends an API call which returns the data in specific order, so each time you click to toggle sorting by a specific value or order, it sends that data through POST, and at the back end there is logic like following for all the columns
ORDER BY $colname $direction
The problem is that some of the data rendered in the table are not contained in a specific table in DB, but in a json, in a column called 'other'. Is there an easy way, or 1 line query that can modify ORDER BY command to work with a specific element in JSON?
Related
Hi, so I have this database project I'm working on that involves transcribing archival sources to make them more accessible.
I'm revamping the database structure, so I can make the depiction of the archival data more accurate to the manuscript sources. As part of that, I have this new table, which has both the labels/titles for columns of data in the documents, plus a "used"field which acts both as a flag for if the field is used, and also for what position it should be in left to right (As the order changes sometimes).
I'm wondering if there's a way to pair the columns together so I can do a query that - when asking for a single row to be returned= sorts the "used" functions numerically (returning all the ones that aren't -1), and also returns all the "label" fields also sorted into the same order (eg if guns_used is 2, and men_used is 1 and ship_name_position is 0, the query will put them in the correct order and also return guns_label, men_label and shipname_label in the correct order).
I'm also working with/around wordpress, so I have the contents of the whole wpdb thing available to me too.
I'm hoping to be able to "pair" the fields in some way so that if I order one set, the other gets ordered as well.
Edit:
I really would prefer to find a way to do this in a query but until I find a way to do that I'm going to
a)Select the entire row that I need
b)Have a long series of if statements- one for each pair of _label/_used fields- and assigning the values I want to the position in the array indicated by the value of the _used field.
One of the fields in my seller db has following data:
{"delivery area":"delivery amount"}
An example of this data in the db is as follows:
{"1":"0","2":"0","3":"0","4":"200","5":"1"}
Now I want to write a query that picks all sellers that deliver to a particular delivery area.
How can I do it using SQL? What do I specify in the WHERE clause?
I am working on Magento so an equivalent in addFieldToFilter will also help.
I just realized that this value is nothing but a json encoded value. All I had to do was to decode it upon reading and extract the values.
Sorry if I am repeating the question, I have a HTML FORM page which displays the employee_id & attendance check box (IN, OUT) using datatable.
I made pagination with initial load value in the screen as 10, the data are loaded from mysql DB and all the data loads perfectly with pagination. I will update attendance status of each employee which checkbox and submit the form.
Once i submit the form, i called the PHP _POST (if(isset($_POST['save']))) , inside this i am trying to get the value of all employee_id & checkbox value but, i can able to get only first 10 rows, remaining in page 2,3,4,5 are not available, is there any option to get them, i tried with jquery for each too but it also alerts on first 10 rows.
Please help me out.
I need to post the data to database from data table regardless of pagination either using PHP post method (or) Jquery.
If you using pagination by LIMIT in database query there is, of course, no way you would get more than 10 rows, so, your <form> submit will not give you more than those 10 data arrays you can save to database.
Can you explain why you need to update all rows in database? Because limiting by pagination guarantees that other rows will not be affected (if query is right).
i got some problem in sending the html table value as form data to the php file.
My problem is..
i have dynamic html tables(which are more than 20 tables) which are created by javascript.
This dynamic tables has dynamic data which is entered by the user. Here i am saving these dynamic data in to the tables.(which is in the table row and table column tags).
Here is my doubt is how to send the these dynamic data tables to my PHP file..
Here my data attributes are dynamic (like id, name and class).
I searched in the google.com and i found the one solution. some thing like place the hidden input tag in your table..
if i do that i will get one more problem.
as previously i said that my data attributes are dynamic. if i do the hidden input values how can i get those value to php file..
I mean, suppose i have 20 rows in each table if send those data to php file, how can i find which data is belong to which table..
Here my every table has 20 rows each. Each row has the dynamic name(which is same to all 20 rows in a table).
please suggest the best way to get rid of this problem.
One way would be, you can loop all the tables and get the values of the first four table cells(TD) for each row in the table, assuming all the tables have same columns, and generate a json javascript object and send that object to your server via javascript.
sample:
var data = {
'department1': {
'eventname': 'xyz',
'emailid': 'x#xyz.com',
'registrationfee' : '300',
'studentname': 'me',
'contactno': '999999999'
},
'department2': {
'eventname': 'xyz2',
'emailid': 'y#xyz.com',
'registrationfee' : '500',
'studentname': 'me2',
'contactno': '9999988888'
},
.....
};
and send the data via post ajax call using jquery or plain javascript.
You can access the data on the server side. If you are using a php framework it might automatically decode the json and gives you an array orthewise you might have to use json_decode().
Hope this gives you a fair idea on how to do it.
Edit:
I mean, suppose i have 20 rows in each table if send those data to php file, how can i find which data is belong to which table..
On that, you are saying that the tables are generated from javascript for each department then add a data attribute to the table to identify the which department the table belongs.
<table data-department="department1"></table>
So I have several form elements which are currently acting as filters - I plan to use this as a basis for a search feature on my website.
I was thinking about linking a set of on change events to dyanmically build an AJAX query that selects fields from a set of tables but I'm not too sure how I can go about doing it.
On page load I have the following: http://jsfiddle.net/uVhzZ/. The pseudo SQL for this setup would be: SELECT * from ts_rooms WHERE capacity >= 50 (Any means no WHERE condition has been set)
However when the user starts to make changes, I would like this additions to be dynamically added to the SQL query - for instance if Lecture Style is set to Lab and capacity changes to 75 then pseudo SQL would change to SELECT * from ts_rooms WHERE capacity >= 75 AND lectureStyle="Lab";
How do I go about doing this?
First you gotta prepare your AJAX request, it can be done by creating an array with all selects you wanna use (you can look on ther .val() and if it has any value you add this value to that array using the select id as array key) then converting it to JSON.
PHP will receive this JSON string and convert it to array. Then you can look thru this array, and for each element you go building your where statement.
Then it's just a matter of taking query resultset and build another array from it, converting to JSON and responding to JS.
Put all your elements in a form, post it to your php search file. Created a sql query with the relevant constraints and return data in json and display it.