0

Use-Case: A react app that also has a little (important) feature that opens a new page (on a new window) upon clickEventHandlers, and displaying results using PHP code in order to parse through a result that is an HTML report from a SQL query. I have used PHP to parse through the resulting output that's in HTML with the help of strpos, and several loops, and this was easy for me. I simple echo the page on the front. For the most part of this app, it's a SPA, but there's a need to open a new page for this report and to customize its "table views".

I only know how to do this via PHP and I wish we could do this via React but I have no idea how to fetch the resulting output (that's in HTML) in json, and then parse through it and map it out to the front end as React does not read HTML code.

I see create-react-app is good for SPAs, but I don't see anyone using any PHP whatsoever for the backend. Is create-react-app even a good approach? I know it utilizes .html pages and not .php so I don't know any way to utilize the PHP I got to parse the html output for this feature.

Is there another approach to solve this problem?

OrangeLime
  • 105
  • 3
  • 10
  • Not sure if I understand your question right but do you want to retrieve the data in the background and convert your HTML to JSON and use those date on your main page? – Peter M Aug 18 '17 at 22:52
  • No. There's a sql query that would run in the backend via PHP, (oci8) and return a json object. My whole react app works like this with the help of ajax requests. And it works nicely, until this one feature. My workaround was to simply use a
    to submit my necessary parameters to the backend PHP and run a query for a specific report that comes in HTML. Good thing about PHP is you can echo HTML so I parse through the resulting HTML, do the necessary filtering views and simply echo the output on a .php page, rather than returning the json object to display it on React.
    – OrangeLime Aug 18 '17 at 22:56
  • It's important to filter the resulting HTML output, but I don't know of a way to go through that resulting output via JSON because the html comes as a string, and react does not like HTML in string. So I can't even filter the table views the way the client desires. – OrangeLime Aug 18 '17 at 22:57
  • I think i understand your problem, can you give me an example of the current output and what you wish to do with it? – Peter M Aug 18 '17 at 23:02
  • I don't have an example to show you, my project's on my work machine. Not on this one, however, what the client desires is this: There are historical reports generated with the help of SQL queries ( Giant reports that are important for DBAs), that currently I parse through with PHP and it's made my life easier. I would love to go with this approach. But is there another way where, I can open a new window(page), display this report with react JSX, once I retrieved the report in JSON format? The whole report's in HTML, but I also need to filter out a few tables in this report - – OrangeLime Aug 18 '17 at 23:10
  • and so far PHP has helped a lot since I can execute SQL queries, echo HTML, and even run shell commands through it. If there are third party tools available for react, that would be awesome. But I hope you see the problem. – OrangeLime Aug 18 '17 at 23:11
  • Maybe this can help: https://stackoverflow.com/a/12984095/838980 it converts HTML into JSON – Peter M Aug 18 '17 at 23:15
  • Or do it with PHP: https://stackoverflow.com/a/23427469/838980 – Peter M Aug 18 '17 at 23:19
  • The first one, mapping html to json, I actually thought of that. Is that actually doable???I mean, wow. – OrangeLime Aug 18 '17 at 23:26
  • Yeah personally I'd prefer to do this server-side though :-) – Peter M Aug 19 '17 at 18:30

0 Answers0