Link to home
Start Free TrialLog in
Avatar of bschwarting
bschwarting

asked on

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

Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

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
Avatar of DavidSingleton
DavidSingleton

You could have your update on another page and call it via ajax.  Then just have your javascript call a page refresh.
Avatar of bschwarting

ASKER

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?
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.
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
ignore the comments about forms, I have decided to do this with get instead of post :)
Am I missing something or is moving the insert query to before the select query not an obvious answer?
ASKER CERTIFIED SOLUTION
Avatar of v2Media
v2Media
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i love a simple answer!  genius!
Genius!