Nic Parmee
Nic Parmee

Reputation: 153

How to send a post to a php file that contains html, javascript and php

I am struggling to update my php file that is the index page of the website (displays the visuals and updates the tables).

I have three files involved the index.php file containing html, php and javascript.

The index code file which the index.php file calls a function in it to get the variables for the table.

And lastly the updatetable file which gets a request from a mobile device and updates the table (as well as many other things but I am just simplifying).

I have been trying to communicate with the index file from the updatetable file just to let it know that it should update its tables. But to no avail.

index.php

<table id= "ptable" class="packed-table" cellpadding="11"><tr><th>Order ID</th><th>Customer</th><th>Vendor</th><th>Address</th><th>Cart_ID</th><th>Cart</th><th>Fetched</th></tr>

<?php
function hope($packed){

       while($row = mysqli_fetch_row($packed)){

echo "<tr id=".$row[0].">";
echo '<td>',$row[0],'</td>';
echo '<td>',$row[1],'</td>';
echo '<td>',$row[4],'</td>';
echo '<td>',$row[7],'</td>';
echo '<td>',$row[2],'</td>';
echo '<td>',"items",'</td>';
?>
<td>
<button id="buttonfetched" onclick='orderFetched("<?php echo $row[0]; ?>","<?php echo $row[2]; ?>")'  name="fetched" >Fetched</button>
</td>
</tr>
   <?php } }
       $packed = $ic->packed();
       hope($packed);
    ?>
</table>

I've tried calling this function but for some reason it just returns the whole html document to my mobile application.

Any help or guidance would be much appreciated.

Upvotes: 0

Views: 49

Answers (1)

Volvox
Volvox

Reputation: 1649

If I'm understand you corretly you want to refresh index on one device then there is update in updatetable from other device (or just different browser tab. Correct?

If so then you cannot do that directly. PHP renders page which is then delivered to user so you have no control over it anymore.

Simplest solution is to refresh (via JavaScript) index every x seconds (full page refresh or just Ajax call in background to check for changes).

For better solution you can use websockets to establish permanent connection and listen for changes in your table, but PHP is not very good for this.

Lastly you can try WebRTC for direct communication between index and updatetable, but I'm not familiar with this technology it, so I'm not sure how mature it is and how exactly make it work.

Upvotes: 1

Related Questions