flex php mysql - post multiple rows of data - php

There are a few examples on the web showing how to post a row/form to mysql with flex php. I think it will be valuable if it allows user to post multiple rows of data. Supposed I have a datagrid and its id is myDG, how can I post the datagrid data to a table in mysql? I am using Flash Builder 4 and I need a solution based on Flex 3/4 + PHP + MySQL. Any suggestions?

I think this should be done this way:
Create a ValueObject class with several params, some used in the data grid and some not.
Insert dynamically using DataGrid.dataProvider.addItem(myValueObject);
Create a PHP function with 2 params, $number_of_rows (in flex is DataGrid.dataProviderLength), and the other param is $item, with is the DataGrid.dataProvider.
The INSERT function might be something like this:
INSERT INTO table (producto, id, precio, stock)
VALUES ("$producto", "$id", "$precio", "$stock")
, ("$producto2", "$id2", "$precio2", "$stock2")
//this must be repeated the number of rows
, ("$productoN", "$idN", "$precioN", "$stockN");
//Several times
Sometimes after placing the call in flex the data is not inserted, so you need something like this myphpService.commit();
I will try to make a full example later.
Thank you.

Related

Laravel query json column array

I am trying to access specific data in a json column using a laravel controller, the DB column is called 'figuresinorder'. I want to access the "wants" key but it's not working when there are multiple values stored.
{"wants": ["1"], "trades": ["12,33,234"]} - this works
{"wants": ["1,2,3"], "trades": ["12,33,234"]} - does not work
The query in the controller is as follows:
$figures2 = customtrades::whereJsonContains('figuresinorder->wants', ['1'])->get();
Any help will be greatly received, been stuck on this for longer than I dare to admit.
MySQL & PostgreSQL support whereJsonContains() with multiple values like this way :
customtrades::whereJsonContains('figuresinorder->wants', ['1','2','3'])->get();
For more, see the documentation here

Get values from an auto-generated table (generated by dhtmlxgrid) and set it to a php variable

EDIT: Ok, i found a way to get the cell-content and make a javascript variable (via dhtmlxgrid functions, something like var leadID = mygrid.cells(id,1).getValue();).
Now the remaining question is how i can get this javascript variable to be available in php for my sql query. On first pageload, since one of the table-cells should display the amount of comments made for this customer.
I need a query like (query is made on first pageload, to feed a cell with data)
$query_entryNo = mysql_query("select count(*) as total from comment WHERE post_id = $leadID ");
Where $leadID is the UserID you see in column 2 on screenshot.
End Edit
probably can ignore the text below...
Hello, i have something i dont know the answer and cannot find a way to do it.
Some info first:
I have an autogenerated table that is build with the help of dhtmlxgrid plugin (javascript). The table that is generated has no class or ID, also not the cells themself and i dont want to mess around with the plugin-sourcecode, for various reasons. So the table will stay class- and id-less.
Every row in this auto-generated table displays a user with his userID, name, email and all that.
I need to fetch this userid for an sql query. I would need this already on first pageload, not after some post or something like that. One column will contain the amount of comments that one made for this user and this i do with sql/php, soo i need some way to get the right db-entry. Comments are linked to the userid, thats why i need the id to be included in the php code for sql-query.
How can i achieve this? Basically the question is how i can get the id shown in column 2 into an sql query.
The screenshot shows the ID in the table that i somehow have to have in my sql query.
Since this table is generated through javascript and the comments are stored in another table i cannot use the basic dhtmlxgrid functions to do this. I have to build around my own way.
Based on our Discussion in the comments I can give you this Solution:
Send Data from PHP to Javasript (at Site-Creation time on Server side): just add a echo "<script>var data=$data; </script>", if it is more complicated you have to convert it into JSON (google that).
To send data on-the fly from Javascript to PHP you need a PHP-side recieving page, that reads your POST-Data. To send the request just use jquery.post like this:
$.post("http://example.com/ajax.php", data);
This will send an asynchronous call to your server.
So in your case, you read the values from the table via Javascript, save them into an array, and prepare the data that it will be interpreted the right way by PHP-Post mechanism:
ajaxData = "";
for (int i = 0; i < tableData.length; i++) {
ajaxData += "data[" + i + "]=" + tableData[i] + "&";
}
$.post("ajax.php", data); //This will take the relative path to your site
You see, that POST data has to be encoded the same way as GET-data.
Hope I could help.

How to sent dynamic html table data from html form to php file

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>

Dynamically build AJAX request based onChange event in form

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.

does anyone know how to add multiple rows into database with mysql and php?

I m designing a website in which I want to add multiple rows into database on single click.
I want to add the results of the students of whole class in the students database which contains columns "s_id, subject_name, subject_result". I have design a simple form which list all the students and a text box in which result is to be added and on the submit button the results to be updated on the students database.
plzz give me some suggestions or link
There's a very good example on how to achieve this using PHP's implode statement right here in this very site. Mind you, I'm not sure what DB you're using but I'm going under the assumption that you're using a *AMP stack.
INSERT INTO results (`s_id`, `subject_name`, `subject_result`)
VALUES (1, 'a1', 's1'), (2, 'a2', 's2'), ...;
If they are submitting the information via a form then the variables should be in an array. You can just loop through the array inserting into the database upon each loop.
I know it's not multiple multiple rows being inserted at once, but it is very fast and works. I've used this method to insert thousands of records at a time with this.
Hope it helps.
Take care,
Shannon

Categories