Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

PHP mysql refresh

I'm open to other technologies if needed, because I can't seem to accomplish what I want with my current setup.  Right now I do an insert on a page.  When I insert, I post some values to the same page URL (amount of days to look back).  I want the user to stay on this same page because they could have 60 items to update, one by one.  Every time they hit update, I want the page to refresh with the new updated list, which is basically minus one item that they just updated.

An example user (before hitting update button):
Date1 Yes/No UpdateButton
Date2 Yes/No UpdateButton
Date3 Yes/No UpdateButton
Date4 Yes/No UpdateButton (they will choose yes here)

An example user (after hitting update button):
Date1 Yes/No UpdateButton
Date2 Yes/No UpdateButton
Date3 Yes/No UpdateButton
(this one is gone now, because it no longer is a missed value that they need to update)

How can I accomplish this?
// FIND OUT WHAT DATES ARE MISSING FROM A CALENDAR TABLE, CALENDAR TABLE HAS ALL DATES FROM 2008-2018 TO COMPARE TOO
$sql1 = "SELECT (calendar.date) as missed_dates from calendar left join $createtablename on calendar.date = 
$result = mysql_query($sql1) or die ("Error in query: $sql1. ".mysql_error());
mysql_query($sql2) or die ("Error in query: $sql2. ".mysql_error());
 
// SIMPLE INSERT COMMAND
if (  (mysql_num_rows($result) > 0) && ($date1 != '' ) ) {
$sql2 = "INSERT INTO $createtablename (date, timesubmit, answer) VALUES ( ' $date1 ' , ' $timesubmitcombine ' , ' $answer ' ) ;"
 
// CREATE A TABLE OF VALUES THAT ARE LEFT OVER
if (mysql_num_rows($result) > 0) {
     echo "<table border=0>";
          echo "<tr>";
          echo "<td width=128><b>Date</td>";
          echo "<td width=69><b>Answer</td>";
          echo "<td width=125><b>Time (Hour-Min)</td>";
          echo "</tr>";
     echo "</table>";
     while(list($date,$timesubmit,$answer)  = mysql_fetch_row($result)) {
     echo "<table cellpadding=1 cellspacing=0 border=0>";
     echo "<form method=post action=/pages/devotions-update/?updating=1&daysback=$daysback>";
          echo "<tr>";
		  $dateformat2 = date("m-d-Y (D)",strtotime($date));
          echo "<td width=132><font size=2>$dateformat2</font><input name=date2 type=hidden value=$date></td>";
 
          echo "<td width=72><select name=answer><option value=1>Yes</option><option value=0 selected>No</option></select></td>";
          echo "<td width=95><select name=timesubmithour><option value=00>00</option><option value=01>01</option></select><select name=timesubmitminute><option value=00>00</option></select></td><td><input type=submit value='Update'></td>";
          echo "</tr>";
	 echo "</form>";
     }
     echo "</table>";
 
}

Open in new window

0
bschwarting
Asked:
bschwarting
  • 3
  • 3
  • 2
  • +1
1 Solution
 
Lukasz ChmielewskiCommented:
so if the same page needs to update it's values you need to add at the top of it
$var = $_POST[somevalue];
...
if(!empty($var))
{
  update the table with posted values
}
...

//echo the table
0
 
DavidSingletonCommented:
You could have your update on another page and call it via ajax.  Then just have your javascript call a page refresh.
0
 
bschwartingAuthor Commented:
Roads_Roads, i think i am following you, but could you provide more of an example?

DavidSingleton, I love what i have seen from ajax, but don't know jack about it and wouldn't know where to start.  Ideas?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
DavidSingletonCommented:
Go and download Prototype, it's a pretty simple concept to pick up.

Basically, you have one page that does your insert/edit, when you click a button, javascript calls that page behind the scenes and returns the result.  This will allow you to do numerous things without navigating your user from their main page.  Check it out, and if you need more specific examples i can probably give you a few, but the web is full of them.
0
 
Lukasz ChmielewskiCommented:
well, not even a form - GET variable would be simplier
lets say you have a table with a fields
id visible
1  true
2 true
3 true

now the page - this example would create few forms but I guess this works as you want them

$var = $_GET[id];
if(!empty($var))
{
 $q = "update table set visible = false where id = ".$var;
 $r = mysql_query($q);
}

// and the table
$q1 = "select * from table where visible = 'true'";
$r1 = mysql_query($q1);
while($w1 = mysql_fetch_array($r1))
{
   echo" id: $w1[id], visible: $w1[visible]";
  echo"<a href=\"thispageaddress.php?id=$w1[id]\">hide</a>";
}


more or less ike that
0
 
Lukasz ChmielewskiCommented:
ignore the comments about forms, I have decided to do this with get instead of post :)
0
 
v2MediaCommented:
Am I missing something or is moving the insert query to before the select query not an obvious answer?
0
 
v2MediaCommented:
Perhaps not. What about repeating the select query after the insert query so the table has the latest records to display in the table?
0
 
bschwartingAuthor Commented:
i love a simple answer!  genius!
0
 
bschwartingAuthor Commented:
Genius!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now