Advertisement

05.07.2008 at 01:01PM PDT, ID: 23384108
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.3

Update Multiple Rows PHP/MySQL/Dreamweaver

Asked by costellom in PHP and Databases, PHP Scripting Language, MySQL Server

Tags:

I have a series of 16 images. The image locations and associated text elements are stored in a MySQL database.

They normally display like this: http://costello-media.com/stx/gallery.php with a basic Dreamweaver PHP SELECT statement.

The Client wants to be able to adjust the order of the images after I'm completed. So I'm trying to build a page that calls up all the rows and the associated order numbers in text boxes. The client would then be able to change the order number, for as many as he likes, then hit submit and all the order numbers that have been changed would updated in the database.

AT this point I have the following code in the form:

<form id="seq_form" name="seq_form" method="POST" action="<?php echo $editFormAction; ?>">
          <?php do { ?>
            <table width="250" border="0" cellpadding="1">
              <tr>
                <td><img src="images/gallery/thumbs/<?php echo $row_pics['thumb_url']; ?>" alt="thumb" width="150" /></td>
                <td><label>
                  <input name="order" type="text" id="order" value="<?php echo $row_pics['order']; ?>" size="3" />
                  <br />
                  <input name="id" type="hidden" id="id" value="<?php echo $row_pics['id']; ?>" />
                </label></td>
              </tr>
            </table>
            <br />
            <?php } while ($row_pics = mysql_fetch_assoc($pics)); ?>
            <label>
            <input type="submit" name="button" id="button" value="Submit" />
            </label>
           
            <input type="hidden" name="MM_update" value="seq_form" />
        </form>

and the following in the header:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "seq_form")) {
  $updateSQL = sprintf("UPDATE gallery SET `order`=%s WHERE id=%s",
                       GetSQLValueString($_POST['order'], "int"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_stx_gallery, $stx_gallery);
  $Result1 = mysql_query($updateSQL, $stx_gallery) or die(mysql_error());

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

mysql_select_db($database_stx_gallery, $stx_gallery);
$query_pics = "SELECT * FROM gallery ORDER BY `order` ASC";
$pics = mysql_query($query_pics, $stx_gallery) or die(mysql_error());
$row_pics = mysql_fetch_assoc($pics);
$totalRows_pics = mysql_num_rows($pics);
?>

It appears to me, based on what I've read elsewhere on EE, I need to do a while loop. My attempts at it have failed. I'm not tied to the Dreamweaver code, meaning I'm pretty comfortable with doing some "hand"coding, but I think I really need help on this.

Thanks in advance.Start Free Trial
[+][-]05.07.2008 at 06:36PM PDT, ID: 21521737

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.08.2008 at 02:28AM PDT, ID: 21523339

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language, MySQL Server
Tags: PHP MySQL
Sign Up Now!
Solution Provided By: Squinky
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628