Jump to content

Updating Multiple Rows at once


m1a2x3x7

Recommended Posts

Hey guys,

 

A client of mine would like to be able to turn on and off zip codes for certain states. So on the admin side of things I have two radio buttons on and off one has a value of 1 on the other has a value of off. I want them to be able to set all the zip codes to on and off at one time with one submit.

 

I have everything working except for multiple zip code changes it will only update the first one.

 

Here is my code.

 

ob_start();

//CONNECT TO DATABASE//
require_once("connection.php");



//PULL INFORMATION FROM THE DATABASE//
$query = sprintf("SELECT * FROM zipCodes");
$result = @mysql_query($query);
$row = @mysql_fetch_array($result);

//VARIABLES//
$active ="green.jpg";
$deactive ="red.jpg";
$radio1 = $_POST['radio1'];
$radio2 = $_POST['radio2']; 

//UPDATES ZIPCODE STATUS//
if (isset($_POST['submit']) && $radio1 == 1) {
    $query =sprintf("UPDATE zipCodes SET active = 1 where test_id = '$zipID[$i]'"); 
    $result = @mysql_query($query);

    $query = sprintf("SELECT * FROM zipCodes");
    $result = @mysql_query($query);
    $row = @mysql_fetch_array($result);

}elseif (isset($_POST['submit']) && $radio2 == 0) {
    $query =sprintf("UPDATE zipCodes SET active = 0 where test_id = '$zipID[$i]'"); 
    $result = @mysql_query($query);

    $query = sprintf("SELECT * FROM zipCodes");
    $result = @mysql_query($query);
    $row = @mysql_fetch_array($result);

}

     

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.font {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
}
#wrapper {
    margin: auto;
    height: auto;
    width: 800px;
}
.tableItems {
    margin: auto;
    height: auto;
    width: 410px;
}
.items {
    height: auto;
    width: 410px;
    margin-top: 10px;
    margin-right: auto;
    margin-bottom: auto;
    margin-left: auto;
    clear: both;
}
.submit {
    text-align: right;
    height: auto;
    width: 80px;
    margin-left: 490px;
    margin-bottom: 10px;
}
.footer {
    clear: both;
    height: auto;
    width: 600px;
}
.status {
    height: auto;
    width: 80px;
    float: left;
    margin-left: 30px;
    text-align: center;
    margin-bottom: 10px;    
}
.onOff {
    height: auto;
    width: 80px;
    float: left;
    margin-left: 30px;
    text-align: center;
    margin-bottom: 10px;
}
.zipcode {
    text-align: center;
    height: auto;
    width: 80px;
    float: left;
    margin-bottom: 10px;
}
-->
</style>
</head>

<body>
<div id="wrapper">
<div id="TabbedPanels1" class="TabbedPanels">
  <ul class="TabbedPanelsTabGroup">
    <li class="TabbedPanelsTab" tabindex="0">Indiana</li>
    <li class="TabbedPanelsTab" tabindex="0">Kentucky</li>
    <li class="TabbedPanelsTab" tabindex="0">Ohio</li>
    <li class="TabbedPanelsTab" tabindex="0">Illinois</li>
  </ul>
  <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent">
      <div id="TabbedPanels2" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0">Zip Code</li>
          <li class="TabbedPanelsTab" tabindex="0">County</li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="font"> <br />
            Indiana Zip Codes<br />
            <br />
            <div class="tableItems"><div class="zipcode">Zip Code</div><div class="status">Status</div><div class="onOff">On
              </div><div class="onOff">Off</div>
            <div class="footer"></div></div><form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
           <?php do { ?> <div class="items"><div class="zipcode"><?php echo $row['zip_code'];?></div>
           <div class="status"><img src="images/<?php if ($row['active'] == 1) {
    echo $active;
    }elseif ($row['active'] == 0) {
    echo $deactive;
    }?>" /></div>
           <div class="onOff">
             <label>
             <input name="radio<?php echo $row['test_id'];?>" type="radio" id="radio1" value="1" <?php if ($row['active'] == 1) {
    echo "checked = \"checked\"";}?> />
             </label>
              </div>
           <div class="onOff">
             <label>
             <input name="radio<?php echo $row['test_id'];?>" type="radio" id="radio2" value="0" <?php if ($row['active'] == 0) {
    echo "checked = \"checked\"";}?> />
             </label>
           </div>              
              <div class="footer">
          </div></div><?php } while ($row = @mysql_fetch_array($result));?><br /><div class="submit">
            <input name="hiddenField" type="hidden" value="1" />
            <input name="submit" type="submit" id="submit" value="Submit" />
          </div></form>            
          </div>
          <div class="font">Indiana Counties</div>
        </div>
      </div>
      <p> </p>
    </div>
    <div class="TabbedPanelsContent">
      <div id="TabbedPanels3" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0">Zip Code</li>
          <li class="TabbedPanelsTab" tabindex="0">County</li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="font"><br />
          Kentucky Zip Codes</div>
          <div class="font"><br />
          Kentucky Counties</div>
        </div>
      </div>
      <p> </p>
    </div>
    <div class="TabbedPanelsContent">
      <div id="TabbedPanels4" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0">Zip Code</li>
          <li class="TabbedPanelsTab" tabindex="0">County</li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="font"><br />
          Ohio Zip Codes</div>
          <div class="font"><br />
          Ohio Counties</div>
        </div>
      </div>
      <p> </p>
    </div>
    <div class="TabbedPanelsContent">
      <div id="TabbedPanels5" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0">Zip Code</li>
          <li class="TabbedPanelsTab" tabindex="0">County</li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="font"><br />
          Illinois Zip Codes</div>
          <div class="font"><br />
              Illinois Counties
          </div>
        </div>
      </div>
      <p> </p>
    </div>
  </div>
</div>
<script type="text/javascript">
<!--
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
var TabbedPanels2 = new Spry.Widget.TabbedPanels("TabbedPanels2");
var TabbedPanels3 = new Spry.Widget.TabbedPanels("TabbedPanels3");
var TabbedPanels4 = new Spry.Widget.TabbedPanels("TabbedPanels4");
var TabbedPanels5 = new Spry.Widget.TabbedPanels("TabbedPanels5");
//-->
</script>
</div>
</body>
</html>

 

and here what it looks like right now.

 

http://www.schultzstudio.com/freelance/index.php

 

I'm pretty sure I need to use an array but I can say I've really experimented with them so any help would be great.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.