dynamically populating textfields in Flashbuilder - php

I'm trying to wrap my brain around getting data into my project in a way that I can use. I want to use MySQL & PHP my Flashbuilder app and I'm not populating a datagrid so.
For simplicities sake, in my database table I have 3 columns "ID, Title & Content".
I want to use this to populate the different states in my flashbuilder project.
Normally in a web page I could say in the sql statement SELECT * FROM table WHERE ID = 1
to get the first row of info and I could put my Title and Content where I want them on my page
I can change the query to SELECT * FROM table WHERE ID = 2 to populate page 2 to get it's title and content.
In flashbuilder it all on the same page and I'm not understanding how to populate a singular text field for a title or content area with a single field from the database.
It seems all the examples on the web are basically for datagrids.
Can someone please help me out?

I'll try to help.
You have the database table (ID, Title, Content).
Go ahead and create a web service in PHP that will ping the database and retrieve the data. I don't know much about PHP, so can't help with specifics. If possible, I recommend using something like AMFPHP or ZendAMF to transfer data back and forth between Flex and PHP.
In Flex, you can retrieve the data using RemoteObject, WebService, or HTTPService. You'll get the data back somehow. For the purposes of this sample, I'll assume you're using a form of AMF and have an array of value objects.
Each object contains an ID, title, and content property, representing a single row in your database table.
Now, what do you do with that array? It would be odd to try to display a collection of data in a single text input. Let's pretend you want to create a form to edit the first item:
<Form>
<formItem label="title">
<textInput id="titleInput" text="{resultsFromPHP[0].title}" />
</formitem>
<formItem label="content">
<textInput id="contentInput" text="{resultsFromPHP[0].content}" />
</formitem>
<formItem >
<button label="Process Input" click="processInput()" />
</formitem>
</form>
So, you have a form that allows for inputs, and has a button. Just write the click handler:
protected function processInput():void{
resultsFromPHP[0].content = contentInput.text
resultsFromPHP[0].title = titleInput.text
// call other PHP Service to update data
}
Does that help?
This was psuedo code I wrote in the browser and will most likely need tweaking to compile.

Related

How to retrieve table row data in php by using an <a>(link)?

I want to implement an inventory table visible below. What I want to know is how to retrieve a table row data, for example when I click the "edit" link from the row of "Item One", I can retrieve it's Item ID "A00". Well, the rest will be up to me after I retrieved that row data. I just want to know first how to retrieve it.
Please be informed that I have already displayed the table shown using php, retrieving of table row data by clicking those <a> links is the only thing I need to know. Please give me a hint on how to do it, I really need it for our project. This is important to us, any help would be appreciated, thank you very much for your ample time!
Use jQuery Ajax and pass your ID as a parameter to the PHP file. Then your PHP file fetches the respective row from your database table.
Alternatively, you can just use jQuery/Javascript to load the content of the current row into the form and 'on update' you can update your database row with the new values. Ajax can also be used in this case so that the page doesn't refresh.
Try this:
Using jQuery ajax you can pass the ID of that record to php file.
Inside that file, You can retrieve the data of that row using ID you passed. For that, use SELECT query to get row data.
Then pass data to jQuery response to use it in the form to display.
Thanks

PHP on a site with dynamic content

SO FAR I have made a website which is connected to a MYSQL database. On the website I have many buttons, each button corresponds to a table in my database. When I click the button, a javascript function opens my php file in this form
xmlhttp.open("GET", "addPoint.php?q=" + name, true); Where name is the name of the table
Back to the html. I have a div with an ID that will update with whatever the PHP echos.
The div is now populated with table, reflecting the table in mysql. This all works fine.
Here is the problem: I am trying to implement a voting system, where you vote by clicking on one of the elements of the newly created table. AFAIK the MYSQL updating which will need to happen for the vote to work, will need to be done in PHP, which means that I need to tell the PHP file
The name of the table
The name of the element
I am reluctant to use forms because I would like to just be able to click some text, NOT have to fill in a form or click a radio button.
So how do I get these 2 bits of info to a PHP file? Is the structure which I am doing this any good or should I step back and redesign?
Thanks for reading please let me know if I have been ambiguous.
Familiarize yourself with JQuery. It's great for projects like these.
http://www.w3schools.com/jquery/default.asp
As Norse already alluded to, use javascript to submit a "form" request for you. The javascript can populate the table and element values for you based on the button which was clicked. It is up to you whether this is a GET/POST.
JQuery would be a great way to help make this easier, but you don't need it if you don't want it.

passing a dynamic html table to php as an array

I have a dynamic html table( rows are added dynamically using java script) and I want to pass whole table to a php script as an array.Is there a way to insert the table data to an array?
I have tried using phpTableExtractor but it dosen't extract dynamically added rows.
I don't see any other reliable solution but creating a HTML form along with the table and have the user click a submit button to save the table. Then you can read all content from $_POST and store it in a database.
Another solution would be to use AJAX requests to store the table content every time the focus changes or something like that. Will make your page dependent on JavaScript though.
What if you fill a JS array at the same time you create the table?
You will use the html just for display but behind you have the data you send to php.

Php Two Combo box in a form control each other. How?

On php page in a form, One combo box has list of my Customer from mysql table customer. Another combo box has invoiceno stored in invoice table which has respective customer records. I want to select customer from first combo box and filter invoiceno from the second one according to the customer. Any one help me for php or java or Jquery or both codeings? Means if I select customer1 then in the second combo box should show all invoiceno respective to the custermer1. No Refresh or ReLoad or Post form Pl. If I get the first selection in a php variable format example $customer, it is enough for me. Thanks for any one help me.
Based on what is given, i think one is only restricted to pushing you in the right direction. In a case where you there a large number of customers, it most likely be that you are working with a database, thus the following process:
The Page of the selects is where you will need to make an AJAX request on change of the select element.
Using your JavaScript of your favorite JavaScript library you'll make the request passing a value that you'll query your database for.
Ofcourse you'll need to configure your PHP for GET or POST depending of you AJAX request, then query the database.
Format the databases output to be a valid HTML of your selected element.
Earlier you'll have configured your AJAX script to populate the proper element once the request has been successful.
You dont want to POST to the script. You dont want to invoke any server side activity. And you want to get the value user selects into a PHP variable. From what I understand, this means, you dont clearly get where PHP plays a role. The way you want it, you might want to use XAJAX : http://www.xajax-project.org But even this causes various REQUESTs to the PHP script internally.
I would suggest the below:
Do a natural join in the SQL query.
For a customer C1, there might be 100 Invoice numbers I1. The result of the query may be outputted in a JSON format. Something like this:
"RESULT" : [
"C1" : ["I1", "I2", I3"],
"C2" : ["I11", "I22", I33"]
]
ALL the data will be sent to the browser. This data can be stored as a Javascript Object. Use JSON.parse("<PHP response here>");
Whenever the users selection changes in a combo box, have a function in Javascript to load the corresponding values in the second list.
EDIT: In case, you are dealing with a larger database, and you expect a larger dataset, I would HIGHLY recommend XAJAX -- Simple and easy! :-)
If AJAX is not an option, you must load all the things (include customer & invoice), then you can use pure javascript/css to do that. It's a dirty work around, but it works.
First, let says that you have n customer, so you will have 1 combo box to select the customer; and n combo box for the invoices that associated with them. Those invoice combobox may have id = their ids in database.
Hide all the invoice combobox, with css : display: none
Use javascript: onchange to get the change event in the customer combobox, then show the approriate invoice combobox(display:block). This can be done easily by css property of Jquery, or simply manipulate by javascript replace function (to replace the html class of the combobox)
I'm sure that this way works, but the price is that you must load all data of customers & invoices, which maybe huge. So that if possible, you should try the AJAX approach like Thrustmaster & Babiker propose.

fetching data from database in randomly generated button

i found it difficult,,,, fetching data from database while a buttons are randomly generated in for each how can i fetch
Without understanding what your question really is, you could go trough the mysql query result like this:
// button_text is a database column in this example
while ($row = mysql_fetch_row($result)){
echo "<button type="button">".$row['button_text']."</button>";
}
But to really help you, you need to rephrase your question!
I'll make some assumptions for what you are trying to do:
1. You have buttons that fetch more info from a db
2. The buttons are "randomly" generated, and each calls different info (pets, cars, etc).
You may or may not be using ajax, but I will describe it basically assuming straight php, and you are using a single page (for clarity in my explanation).
What you need to do is have each button either be a link or a submit for a form. This just depends on whether you want to use GET or POST. The buttons will have php generated links (if GET) or values (if POST). For example, using get the link could be "www.file.php?cat=cars". The button would just have the value of "Cars", and since bother are generated, that shouldn't be an issue keeping them the same.
When the page is now reloaded based on the click, the top of the page has a query in it to get the new info. For example, it would run a query looking for all items that have the car category. Then the new information would be displayed, and the new random buttons would show.
VERY IMPORTANT: Sanitize all GET and POST values before using them in a query

Categories