Is it possible to send the result of a Python script to the input field of a PHP page?
I am using a PYTHON script to capture weight data from a scale. I would like to use that data from the python script, placing it into the input field of a PHP page.
The name of the input field on the page will remain static, as will the name of the page.
To initiate the process (from python script to the input field) I would use an on click command or something similar.
I am very new to python and very much appreciate any help.
Bob
You have to expose the data to the Internet - either create an upload script in PHP that will receive data whenever your Python script captures the new weight (you probably don't want this approach), or write a PHP script that will execute the Python script, take its output and send it back to you. You can then reload the whole page or use JavaScript to update the input field
Hope this helps you, comment if you have any questions
I guess this is what you're looking for
https://stackoverflow.com/a/5986282/7950984 .
Or you could create a server(running your php script) and post data to it, which will use your data as input. For this you could use CodeIgniter or a simplified REST Library RestServer.
Related
I have a textbox where the value is depends on the input type into it.
<input name="convertedcurrency" id="convertedcurrency" type="text" required="required"/>
Is there any possibility that using any PHP code to display the value of the typed value instantly? (I was trying to echo the value using php at another textbox.)
P/S: It must be a php code due to I need this value to combine with other php value for other use.
There is nothing to do with php. You input is rendered and proceeded clientside (in the browser), so all manipulations should be done there too.
You should pass all the values and logic to the clientside, usually JavaScript, maybe with some sort of framework, jQuery, Angular.js, Ember.js, etc. Do manipulations there, and if you need to save something on the serverside, for example in the database - only then pass the data back using AJAX, and then you will need serverside processing with php, pyton, node.js, etc. Whatever is ok for you.
I have a fortran program that I want to call from php with some arguments passed from php via a website.
I have the php form set up, but I don't know how to send the information to fortran. Currently , the information is input to the fortran program through prompts:
write(\*,'("give input image name:",$)')
read(\*,\*) iminput
So I want to send an array, or something similar so I can have
CHARACTER(LEN=*) :: iminput
iminput = post(1)
Or something similar.
If you have a program that expects its parameters on standard input instead of as command line arguments, you can still automate passing the information by using a pipe. For example, if the program asks for your name and age, you could feed these in in one go from the shell, without waiting for it to ask, by doing:
echo -e "user1795485\n1 day" | theprogram
For your problem, you need to be able to run your program, write to its standard input and then read its response back from its standard output. I think proc-open will let you do exactly this. Example 1 on that page is exactly what you want, I think. Basically, you would call proc-open, then write the information the fortran program expects, close the write handle and then read back the results. Note that the fortran program does not need to be modified in any way.
I have a HTML page. Clicking on one link within the page runs a php function which adds a HTML table to the page (implemented with AJAX, php function is in a separate php file).
Now, I have a button on the page which is supposed to run another php function which should pick up the data from the table and do something with it. I don't know how to get the data from the table because:
I don't know how to reference (get) a HTML element through php.
My php function is in a separate file.
What if I put everything from the table in POST or GET arguments? Is there a way to reference the table and iterate its rows and get the data that way? Thanks.
This is not a job for PHP, you should use Javascript to capture the table contents and then manipulate them whatever way you would like. If on the other hand the table contents never change then you can just put them into your PHP function.
You can pull the values of the table by first setting an ID for the table like so:
<table id="someTable">
<tr id="someRow">
<td>Data</td>
<td>Data2</td>
</tr>
</table>
Then you can call the values from the table using JavaScript:
var row = document.getElementById("someRow");
var cellValues = row.getElementsByTagName("td");
This will put all of the cells into an array. Then you can put them into variables.
var firstCell = cellValues[0].innerText;
var secondCell = cellValues[1].innerText;
Then you can put it into an AJAX Request and send it to your PHP function to be processed.
This will send a GET or POST request to yourfile.php and then you can manipulate the cell rows in whatever manner you would like and send back a result by echoing it out in the PHP file. You can retrieve the results by making the callback function.
Hope this helps,
Chris
I don't know how to reference (get) a HTML element through php.
Use JavaScript to get the data from the table.
My php function is in a separate file.
Create another AJAX request to get it processed by PHP,
You cannot reference an HTML Table from PHP. Your JS should just send the table data, extracted out of the html table, as JSON. Your PHP can respond with some more JSON that your JS can use to manipulate the existing table.
A php file that is used as the response to an XHR should not generate JS. Just JSON.
Yes you have to put the data in POST arguments. Do not use GET since the table might get to big. You can use javascript to get all the data from the elements. Send the data with ajax to a php page. Now you can get the post data and so somehting with it (For example persisting).
The reason that you can't get it directly with php is because html and javascript are run by the browser (client side) while php runs in the web server (Server side). You need some sort of communications between these machines to use each others resources.
Problem:
I don't know the simplest way to allow a single web viewer to update data in a text file on a server. (ie. only 1 person will be changing the data.)
Objective:
To make a prototype web application just one person needs to input in the start and end dates of new assignments and locations of staff and the whole company can visualize the information on a GANTT chart, probably using this Jquery libary.
Constraints:
My data is about the equivalent size of 1000 of these javascript list of lists like
*data = [["John Smith" , "assigment" , "1/1/10", "1/1/11", "Peru"],[...],...]*
Employee assignment data must be on an internal server.
I can't use a database (such as SQlite or MySQL).
I can only use PHP, Javascript, and jQuery.
Fact: Javascript cant directly change a data file sitting on the server.
My tentative fuzzy solution:
On client-side: use jQuery getJSON() to pass the data back and forth between dataReadWriter.php.
On server-side: dataReadWriter.php modifies a PHP array as well as writes modified data and reads JSONdata.txt stored in a text file on our internal server.
Given the constraints, it can't be done a lot smarter than what you are suggesting. One thing though, you shouldn't overwrite the only file containing the data, at least switch back and forth between two files, and make sure that your program does not overwrite the other file if one of the files show any signs of being damaged. You can use a PHP session to keep track of which file is the most recent, but better have some in-file timestamps as a fallback.
Is there anything in particular that you worry about?
I've got a script in php that continually grows an array as it's results are updated. It executes for a very long time on purpose as it needs to filter a few million strings.
As it loops through results it prints out strings and fills up the page until the scroll bar is super tiny. Instead of printing out the strings, I want to just show the number of successful results dynamically as the php script continues. I did echo(count($array)); and found the number at 1,232,907... 1,233,192 ... 1,234,874 and so forth printed out on many lines.
So, how do I display this increasing php variable as a single growing number on my webpage with Javascript?
Have your PHP script store that number somewhere, then use AJAX to retrieve it every so often.
You need to find a way to interface with the process, to get the current state out of it. Your script needs to export the status periodically, e.g. by writing it to a database.
The easiest way is to write the status to a text file every so often and poll this text file periodically using AJAX.
You can use the Forever Frame technique. Basically, you have a main page containing an iframe. The iframe loads gradually, intermittently adding an additional script tag. Each script tag modifies the content of the parent page.
There is a complete guide available.
That said, there are many good reasons to consider doing more pre-computation (e.g. in a cron job) to avoid doing the actual work during the request.
This isn't what you're looking for (I'm as interested in an answer to this..), but a solution that I've found works is to keep track of the count server-side, and only print every 1000/5000/whatever number works best, rather than one-by-one.
I'd suggest that you have a PHP script that returns the value in JSON format. Then in another php page you can do an AJAX call to the page and fetch the JSON value and display it. Your AJAX call can be programmed to run perhaps every 5 seconds or so depending on how fast your numbers output. Iframe though easier, is a bit outdated.