Results 1 to 8 of 8

Thread: [RESOLVED] MySQL UPDATE TABLE problem.

  1. #1

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Resolved [RESOLVED] MySQL UPDATE TABLE problem.

    Hi.
    What im trying to do is.Update a table full of max size's.These size's determine the "MAX FILESIZE" that a person can upload to the server with.Depending on their access level.

    The problem im having right now (which probably has a simple solution) is updating the max size.

    I am really stumped.I've tried everything from two foreach's too a for loop.

    This is what the table, that i am using, looks like.


    My problem is of course the updating of the max filesize.Using this code.HTML included.

    PHP Code:
    //----------------------------------
    if(isset($_POST['update'])){
                
        if(is_array($_POST['maxsize'])){
            foreach($_POST['maxsize'] as $size){
        //??????????????????????????????????????? This is where i have the problem.
            }
        }
    }
    //==================================
    $SQL = "SELECT dms.*, acl.* FROM ".DOWNLOADSMAXSIZE_TABLE." dms JOIN ".ACCESS_LVL_TABLE." acl ON dms.accessID = acl.access_id";
    $RESULT = mysql_query($SQL) or print(mysql_error());
    ?>

    <form id="form1" name="form1" method="post" action="download_management.php">
      <table width="31%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
        <tr>
          <td colspan="2" bgcolor="#003366" class="content_header">Download - Max File Size </td>
        </tr>
        <tr>
          <td colspan="2" bgcolor="#003366" class="content_header2">*Note: -1 = Unlimated</td>
        </tr>
        <?
      while($row = mysql_fetch_array($RESULT)):
      ?>
        <tr>
          <td width="42%" bgcolor="#003366" class="content_row1"><div align="left">
              <?=$row['access_name']?>
          </div></td>
          <td width="58%" bgcolor="#003366" class="content_row2">
              <input type="hidden" name="sizeID[]" value="<?=$row['accessID']?>"/>
          <input type="text" name="maxsize[]" class="txtBox" value="<?=$row['size']?>" /></td>
        </tr>
        <?
      endwhile;
      ?>
        <tr>
          <td colspan="2" bgcolor="#003366" class="content_header"><div align="center">
              <input type="submit" name="update" class="txtbox" value="Update"/>
          </div></td>
        </tr>
      </table>
    </form>
    Im stumped on this.
    Last edited by PlaGuE; Jul 24th, 2006 at 04:26 PM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: MySQL UPDATE TABLE problem.

    Im not sure if MySQL supports mutliple updates in the same query, but can you not loop though and create an update query for each item that needs updating?

  3. #3
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Re: MySQL UPDATE TABLE problem.

    What's the UPDATE SQL script you have tried?

  4. #4

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: MySQL UPDATE TABLE problem.

    Quote Originally Posted by john tindell
    Im not sure if MySQL supports mutliple updates in the same query, but can you not loop though and create an update query for each item that needs updating?

    I've tried alot of ways to update them. A few worked...But only changed every "size" value to the same one.


    I know this is probably very simple. But i just cant think of how to do it.

    Like i said in earlier post.

    I tried utilizing a "for" loop and a foreach.One or the other,Both Together.

    Some worked.With ugly results.Others did nothing.


    If i could successfully catch the accessID of the size.I'd possibly able to update the size correctly.

    But i am stumped.

    Edit::


    ROFL... I had thought of doing this earlier...but.. i didnt

    PHP Code:
        if(is_array($_POST['maxsize'])){
            foreach(
    $_POST['maxsize'] as $Key_size => $Key_value){
            echo 
    $Key_size " => " $Key_value."<br /> \n";
            
    mysql_query("UPDATE ".DOWNLOADSMAXSIZE_TABLE." SET size='".$Key_value."' WHERE accessID='".$Key_size."'");        
            }
        } 
    Last edited by PlaGuE; Jul 24th, 2006 at 08:39 PM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: MySQL UPDATE TABLE problem.

    If you want to update only a single field, use the primary key in the WHERE clause to limit the update to just one row. If you use any other field you cnanot garuntee that only one row will be updated.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: MySQL UPDATE TABLE problem.

    For this.I needed ( and have done.) to update all rows.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] MySQL UPDATE TABLE problem.

    Yes, you have updated all rows, but each update contains different data, hence, you have executed multiple queries.
    Code:
    UPDATE tablename SET size=213;
    Will update every row in the table setting the size to 213.

    Code:
    UPDATE tablename SET size=213 WHERE accessid=2324;
    Will update only a single row, assuming accessid is the primary key or has a unique constraint (there is nothing saying that it has to be a primary key however).
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: [RESOLVED] MySQL UPDATE TABLE problem.

    Well.I mean this was the crude way of doing it...

    I mean it's hoping that the accessID is the same as teh array#
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width