Dreamweaver Update Record Server Behaviour & Go To Updated Record

Hi,

I have a master results page (results.php) which displays several hundred database records, retrieved using a recordset and a repeat region.  One can then click on edit to go to a seperate page (update.php) which then uses the Dreamweaver Update Record Server Behaviour.  When I submit the updated record, I'd really like to return to the record's place in the master results list.  Is this possible?

Thanks

J
xtbartonAsked:
Who is Participating?
 
Jason C. LevineNo oneCommented:
Oops.  The update code happens before the recordset code.

Move lines 24-32 from that code snippet to above line 1
0
 
Jason C. LevineNo oneCommented:
Hi xtbarton,

Does the user have to click anything to get to the place in the master list to begin with?
0
 
xtbartonAuthor Commented:
Hi,

Not at present; there are no anchors in the page at all.  It's just a collection of several hundred records organised by date ascending.  

Thanks.  
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Jason C. LevineNo oneCommented:
So you would need to create anchors in order for this to work and pass the anchor to edit page and then have the edit page build it into the URL for the return trip.

The other way to do it would be to get a little clever with AJAX and have your edit form appear in a modal overlay on the list page.  That way, the user never leaves and never loses position.
0
 
xtbartonAuthor Commented:
Thanks; my PHP is a bit limited as yet, so can you offer any more clues?  How do I go about creating the anchor in the repeat region that's passed to the edit page and then how do I submit this as a return variable?  
0
 
Jason C. LevineNo oneCommented:
Can you paste the repeat region section of the table here and I'll give it a shot?

Stepping into a meeting now so I'll be back in an hour or so
0
 
xtbartonAuthor Commented:
Thanks Jason; code is:
      <?php do { ?>
    </p>
    <div align="left">
      <table width="823" border="0">
        <tr>
          <td width="350" height="58"><em><?php echo $row_rsGNresults['newspaper']; ?></em></td>
          <td width="463"><?php echo date("Y F j", strtotime($row_rsGNresults['date'])); ?></td>
        </tr>
        <tr>
          <td height="48" colspan="2"><?php echo $row_rsGNresults['entry']; ?></td>
        </tr>
        <tr>
          <td height="31" colspan="2"><?php echo nl2br($row_rsGNresults['comments']); ?></td>
        </tr>
        <tr>
          <td width="100"><a href="update.php?id=<?php echo $row_rsGNresults['id']; ?>">Edit</a></td>
          <td width="100"><a href="delete.php?id=<?php echo $row_rsGNresults['id']; ?>" onclick="tfm_confirmLink('Are you sure you want to delete this record?');return document.MM_returnValue">Delete</a></td>
        </tr>
      </table>
    </div>
  
   
    <hr />
<?php } while ($row_rsGNresults = mysql_fetch_assoc($rsGNresults)); ?>
</div>

Open in new window

0
 
Jason C. LevineNo oneCommented:
So, after line 2 add this:

<a name="<?php echo $row_rsGNresults['id']; ?>"></a>

That generates the anchor.

Change line 16 like so:

<td width="100"><a href="update.php?id=<?php echo $row_rsGNresults['id']; ?>#<?php echo $row_rsGNresults['id']; ?>">Edit</a></td>

The above will use the id number as both the query string and anchor tag on update.php page.  Dreamweaver SHOULD preserve the # reference in the redirect and the resulting URL will return the user back to the same spot.
0
 
xtbartonAuthor Commented:
Thanks Jason.  I can see now that when I click on a record to edit, it appends the URL with /update.php?id=1705#1705.  Do I need to update the 'go to' statement on the update.php page?  I.e.

 $updateGoTo = "admin/results.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

Open in new window

0
 
Jason C. LevineNo oneCommented:
Does the existing code do the redirect and preserve the # ?

Test it.  If so, there is no further need to edit.  If not...
0
 
xtbartonAuthor Commented:
When I submit the update page, it does maintain the id in the URL of the results page it returns to, i.e. results.php?id=1938.  Unfortunately, it still just takes me back to the top of the results page rather than to the record in the page.

Thanks.  
0
 
Jason C. LevineNo oneCommented:
Okay, so it doesn't preserve the anchor.  Let me figure out how to tweak that code.
0
 
Jason C. LevineNo oneCommented:
On the update page, what is the code for the recordset ID?  I need it to show you how to change the one line in the redirect code...
0
 
xtbartonAuthor Commented:
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE gemnews_tab SET category=%s, `language`=%s, newspaper=%s, `date`=%s, issue=%s, works=%s, entry=%s, comments=%s WHERE id=%s",
                       GetSQLValueString($_POST['category3'], "text"),
                       GetSQLValueString($_POST['language2'], "text"),
                       GetSQLValueString($_POST['newspaper'], "text"),
                       GetSQLValueString(make_date_string($_POST['date']), "date"),
                       GetSQLValueString($_POST['issue'], "text"),
                       GetSQLValueString($_POST['works2'], "text"),
                       GetSQLValueString($_POST['entry2'], "text"),
                       GetSQLValueString($_POST['comments'], "text"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_UtOrpheus, $UtOrpheus);
  $Result1 = mysql_query($updateSQL, $UtOrpheus) or die(mysql_error());

  $updateGoTo = "results.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsGNupdate = "-1";
if (isset($_GET['id'])) {
  $colname_rsGNupdate = $_GET['id'];
}
mysql_select_db($database_UtOrpheus, $UtOrpheus);
$query_rsGNupdate = sprintf("SELECT * FROM gemnews_tab WHERE id = %s", GetSQLValueString($colname_rsGNupdate, "int"));
$rsGNupdate = mysql_query($query_rsGNupdate, $UtOrpheus) or die(mysql_error());
$row_rsGNupdate = mysql_fetch_assoc($rsGNupdate);
$totalRows_rsGNupdate = mysql_num_rows($rsGNupdate);
?>

Open in new window


And in the body:
  <form id="form2" name="form2" method="POST" action="<?php echo $editFormAction; ?>">
      <h2>Update Record</h2>
      <table width="764" height="90" border="0" class="content">
        <tr>
          <td width="276" height="44"><label for="newspaper">Newspaper</label>
          <input name="newspaper" type="text" id="newspaper" value="<?php echo $row_rsGNupdate['newspaper']; ?>" /></td>
          <td width="227"><label for="issue2">Issue</label>
          <input name="issue" type="text" id="issue2" value="<?php echo $row_rsGNupdate['issue']; ?>" /></td>
          <td width="239"><label for="date2">Date</label>
          <input name="date" type="text" id="date2" value="<?php echo date("Y, F j", strtotime ($row_rsGNupdate['date'])); ?>
" /></td>
        </tr>
        <tr>
          <td><label for="category2">Category</label>
            <select name="category3" id="category2" title="<?php echo $row_rsGNupdate['category']; ?>">
              <option selected="selected" value="" <?php if (!(strcmp("", $row_rsGNupdate['category']))) {echo "selected=\"selected\"";} ?>></option>
              <option value="Concert" <?php if (!(strcmp("Concert", $row_rsGNupdate['category']))) {echo "selected=\"selected\"";} ?>>Concert</option>
              <option value="Publication" <?php if (!(strcmp("Publication", $row_rsGNupdate['category']))) {echo "selected=\"selected\"";} ?>>Publication</option>
              <option value="Sale" <?php if (!(strcmp("Sale", $row_rsGNupdate['category']))) {echo "selected=\"selected\"";} ?>>Sale</option>
              <option value="Clocks" <?php if (!(strcmp("Clocks", $row_rsGNupdate['category']))) {echo "selected=\"selected\"";} ?>>Clocks</option>
          </select></td>
          <td><label for="language2">Language</label>
            <select name="language2" id="language2" title="<?php echo $row_rsGNupdate['language']; ?>">
              <option selected="selected" value="" <?php if (!(strcmp("", $row_rsGNupdate['language']))) {echo "selected=\"selected\"";} ?>></option>
              <option value="EN" <?php if (!(strcmp("EN", $row_rsGNupdate['language']))) {echo "selected=\"selected\"";} ?>>English</option>
              <option value="FR" <?php if (!(strcmp("FR", $row_rsGNupdate['language']))) {echo "selected=\"selected\"";} ?>>French</option>
              <option value="HL" <?php if (!(strcmp("HL", $row_rsGNupdate['language']))) {echo "selected=\"selected\"";} ?>>Dutch</option>
            </select>
          <label for="works2"></label></td>
          <td><label for="works3">Works</label>
            <select name="works2" id="works3" title="<?php echo $row_rsGNupdate['works']; ?>">
              <option selected="selected" value="" <?php if (!(strcmp("", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>></option>
              <option value="Opus 1" <?php if (!(strcmp("Opus 1", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 1</option>
              <option value="Opus 2" <?php if (!(strcmp("Opus 2", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 2</option>
              <option value="Opus 3" <?php if (!(strcmp("Opus 3", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 3</option>
              <option value="Opus 4" <?php if (!(strcmp("Opus 4", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 4</option>
              <option value="Opus 5" <?php if (!(strcmp("Opus 5", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 5</option>
              <option value="Opus 6" <?php if (!(strcmp("Opus 6", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 6</option>
              <option value="Opus 7" <?php if (!(strcmp("Opus 7", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 7</option>
              <option value="Opus 8" <?php if (!(strcmp("Opus 8", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 8</option>
              <option value="Opus 9" <?php if (!(strcmp("Opus 9", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 9</option>
              <option value="Opus 10" <?php if (!(strcmp("Opus 10", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 10</option>
              <option value="Opus 11" <?php if (!(strcmp("Opus 11", $row_rsGNupdate['works']))) {echo "selected=\"selected\"";} ?>>Opus 11</option>
          </select></td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <p>
        <label for="entry">Text</label>
        <textarea id="entry" name="entry2"><?php echo $row_rsGNupdate['entry']; ?></textarea>
      </p>
    
      <p>
        <label for="comments">Comments</label>
        <textarea id="comments" name="comments"><?php echo $row_rsGNupdate['comments']; ?></textarea>
      </p>
      
      <p>
        <input type="submit" name="Insert" id="Insert" value="Submit" />
        <input name="id" type="hidden" id="id" value="<?php echo $row_rsGNupdate['id']; ?>" />
      </p>
<p>
  <input type="hidden" name="MM_update" value="form2" />
    </p>
    </form>
    <p>&nbsp;</p>
</div>
  </body>
</html>
<?php
mysql_free_result($rsGNupdate);
?>

Open in new window

0
 
Jason C. LevineNo oneCommented:
Okay, from the redirect code above ( http:#a35745020 ) you want to change line 4 like so:

$updateGoTo .= $_SERVER['QUERY_STRING'] ."#". $row_rsGNupdate['id'];

That should send you back to the correct anchor.
0
 
xtbartonAuthor Commented:
Sadly not; on the update page, the URL looks like update.php?id=1938#1938 and on the results page once an update is sumbitted the URL looks like results.php?id=1938# but it's not taking me to an anchor point.
0
 
xtbartonAuthor Commented:
You're a genius.  Worked perfectly!

Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.