Jump to content

chrisyroid

Members
  • Posts

    10
  • Joined

  • Last visited

chrisyroid's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. After endless google searches I came up with a solution which includes a bit of your last few posts. I changed my Tampermonkey script to count the account tables and send that to my PHP. "&accountsnumber=" + accountsCount Then I modified my PHP to accept that value and used that number to figure out how many entries should be written to my html file. $accountnumber = $_POST['accountsnumber']; $str = '<strong>Updated last: ' . $_POST['date'] . '</strong><br /><br />'; for ($i = 0; $i < $accountnumber; $i++) { $identer = $i + 1; $str.= '<strong>Account ' . $identer . '</strong><br />(' . $_POST['accountname' . $identer] . ')' . '<br />CREDITS<br />' . $_POST['credits' . $identer] . '<br />-<br />'; } file_put_contents("content.html", rtrim($str, '<br />-<br />')); Thank you so much for all your help.
  2. Putting this in my php file writes "..." to my html file. $contents = $mystring . "..."; $n = 1; $accounts = array(); foreach ($_POST["accounts"] as $account) { $accounts[] = "<strong>Account {$n}</strong><br>({$account['name']})<br>CREDITS<br>{$account['credits']}"; } $contents .= implode("<br>-<br>", $accounts); file_put_contents("content.html", $contents); This is what I get now if I use var_dump$(_POST) Object {readyState: 4, responseText: "↵array(2) {↵ ["date"]=>↵ string(58) "Sun Dec 27 … ["credits"]=>↵ string(2) "72"↵ }↵ }↵}↵", status: 200, statusText: "OK"}abort: ( statusText )always: ()complete: ()done: ()error: ()fail: ()getAllResponseHeaders: ()getResponseHeader: ( key )overrideMimeType: ( type )pipe: ( /* fnDone, fnFail, fnProgress */ )progress: ()promise: ( obj )readyState: 4responseText: "↵array(2) {↵ ["date"]=>↵ string(58) "Sun Dec 27 2015 18:35:23 GMT-0700 (Mountain Standard Time)"↵ ["data"]=>↵ array(6) {↵ [0]=>↵ array(2) {↵ ["name"]=>↵ string(28) "****@gmail.com"↵ ["credits"]=>↵ string(3) "110"↵ }↵ [1]=>↵ array(2) {↵ ["name"]=>↵ string(33) "****@gmail.com"↵ ["credits"]=>↵ string(3) "110"↵ }↵ [2]=>↵ array(2) {↵ ["name"]=>↵ string(23) "****@gmail.com"↵ ["credits"]=>↵ string(3) "536"↵ }↵ [3]=>↵ array(2) {↵ ["name"]=>↵ string(32) "****@outlook.com"↵ ["credits"]=>↵ string(3) "333"↵ }↵ [4]=>↵ array(2) {↵ ["name"]=>↵ string(19) "****@gmail.com"↵ ["credits"]=>↵ string(3) "188"↵ }↵ [5]=>↵ array(2) {↵ ["name"]=>↵ string(20) "****@gmail.com"↵ ["credits"]=>↵ string(2) "72"↵ }↵ }↵}↵"setRequestHeader: ( name, value )state: ()status: 200statusCode: ( map )statusText: "OK"success: ()then: ( /* fnDone, fnFail, fnProgress */ )__proto__: Object
  3. I think I know where to change accounts[n] But I can't figure out where to change data[n][credits] And how do I use the above changed code to write to an html file?
  4. I don't quite understand what is supposed to be going on here. Also I just realized that I don't need "$mystring" don't know why that was still in there...
  5. I'm trying to shorten this piece of my code into a loop. I've tried to get the $param_name using: $_POST as $param_name => $param_val But that just gets me the last entry and not the whole thing. Here's the code I'm trying to shorten: file_put_contents( "content.html", $mystring . "<strong> Updated last: " . $_POST['date'] . "</strong><br><br>" . //Please add more entries depending on how many accounts you have configured "<strong>Account 1</strong><br>(" . $_POST['accountname1'] . ")" . "<br>CREDITS<br>" . $_POST['credits1'] . "<br>-<br>" . "<strong>Account 2</strong><br>(" . $_POST['accountname2'] . ")" . "<br>CREDITS<br>" . $_POST['credits2'] . "<br>-<br>" . "<strong>Account 3</strong><br>(" . $_POST['accountname3'] . ")" . "<br>CREDITS<br>" . $_POST['credits3'] . "<br>-<br>" . "<strong>Account 4</strong><br>(" . $_POST['accountname4'] . ")" . "<br>CREDITS<br>" . $_POST['credits4'] . "<br>-<br>" . "<strong>Account 5</strong><br>(" . $_POST['accountname5'] . ")" . "<br>CREDITS<br>" . $_POST['credits5'] . "<br>-<br>" . "<strong>Account 6</strong><br>(" . $_POST['accountname6'] . ")" . "<br>CREDITS<br>" . $_POST['credits6']); Also here's the Javascript code I'm posting with: function bprs() { { var rowCount = $('#accountsTable tr').length; var accountsCount = rowCount -1; var accounts = []; for (var n = 1; n <= accountsCount; n++) { accounts[n] = { name: $('#accountName' + n).text(), credits: $('#credits' + n).text() }; } var date = new Date(); var data = "date=" + date + accounts.reduce(function (prev, account, n) { return prev + "&accountname" + n + "=" + account.name + "&credits" + n + "=" + account.credits; }, ''); I'd like my php page to generate the html code based on how many entries are in the post data. I know I'm close, I just don't know how to loop data like this properly.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.