0

I have an auction site & want to refresh the item page for everyone when the new bid is posted. The item page is called item.php. What I was thinking was that when the new bid is posted to the database when the button clicks, the same click refreshes item.php. The code I'm looking at is

if (!isset($_POST['action']) && !isset($_GET['refresh'])) {
  header("Location: /item.php?refresh");
}|| isset($errmsg))

The original code was

if (!isset($_POST['action']) || isset($errmsg))

but this is not working.

I'm wondering is there a simple onclick solution I can add to the button in bid to refresh item.php for everyone. I also looked at AJAX but I don't understand how to apply it here. Any advice on the best solution to this is appreciated.

maxhb
  • 8,554
  • 9
  • 29
  • 53
  • 1
    There is no 'simple' solution. You need to look into socket connections. – Max Feb 19 '16 at 12:02
  • Use Javascript to refresh the another page – Gopalakrishnan Feb 19 '16 at 12:13
  • Either you need to push the information from server to client (PHP will be tricky here) or you need to pull the data from the client, which you have to do via JavaScript in the client (meaning on the page you want to refresh). – Guido Kitzing Feb 19 '16 at 12:15
  • PHP cannot force a browser to refresh because it runs on the server to generate content. Once the page is delivered to the browser, PHP cannot affect it anymore. You can use javascript to check for whether there is a need to refresh, but it's not the best solution for scalability or speed. – jlemley Feb 19 '16 at 12:20

2 Answers2

1

I would recommend an ajax call that will executed in determined interval, to the server for the latest bid, than you can compare if the bid displayed is up-to-date or not, then if needed you can refresh the page with a location.reload();

stiGVicious
  • 220
  • 1
  • 10
  • This actually came up. The issue I had was that the page has a header, body & footer container and I had issues pulling out the pertinent info for the bids only. What I've done at the moment is put in a 30 second refresh with a timer and a refresh button but its not the cleanest solution. – hhavatar Feb 19 '16 at 14:09
0

You can achieve via using jquery load() method.

You have to call load() method every time when you insert new data.It will simply give all data without refresh page.

For example: $("#yourDiv").load("www.yourdomain.com/item.php).

vipul sorathiya
  • 1,318
  • 12
  • 23
  • Tried this by wrapping the bid button in bid with `

    ` and I'm getting item/php page display in the bottom of the bid.php screen.
    – hhavatar Feb 19 '16 at 14:27