SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why isn`t this working

    Hello all,

    I need some help. This is my database:



    This is the output of my code:



    When I submit the form it only updates the first row. It does not update the second one.



    Can you please help me.
    Thanks

    PHP Code:

    <?
    include_once ("config/connect.php");
    $ref=$_GET['ref'];

    if (isset(
    $_POST['ok'])) 
    {
         
    $item_name $_POST['item_name'];
         
    $worker $_POST['worker'];     
         
    $item_id $_POST['item_id'];

         for (
    $i=0;$i<count($_POST['item_id']);$i++) {

         
    $query5 mysql_query("UPDATE item SET item_name = '".$item_name[$i]."', worker_id = '".$worker[$i]."' WHERE item_id = '".$item_id[$i]."' ") or die(mysql_error());
         }            
    }

    ?>


    <?php
    $query1 
    "SELECT * FROM item WHERE order_reference_number='$ref' GROUP BY item_amount";
    $portfolio mysql_query($query1);
    while(
    $row1 mysql_fetch_array($portfolio)) {
    ?>
    <table width="100%">
    <tr>
    <td valign="top" width="266">
    <?=$row1['item_amount'];?> of 
    <input name="item_name[]" type="text" value="<?php echo $row1['item_name'];?>" size="30" />
    <input name="item_id[]" type="hidden" value="<?=$row1['item_id'];?>" />
    </td>
    <td width="480">
    <?php
    for ($i=0$i<$row1['item_amount']; $i++) {
    ?>
    Choice a worker for this job

    <select name="worker[]" id="">
    <option value="Select">Select</option>
    <?php  
    $query3 
    "SELECT * FROM worker";
    $portfolio1 mysql_query($query3);
    while(
    $row3 mysql_fetch_array($portfolio1)) {
    ?>    
    <option><?php echo $row3['worker_name'];?></option>
    <?php ?>
    </select><br /><br />

    <?php
    }
    ?>
    </td>
    </tr>
    </table>
    <?php ?>
    Rapidme
    (rapidshare application)
    www.rapidme.com

  2. #2
    SitePoint Member IdleServ's Avatar
    Join Date
    Nov 2003
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the contents of $_POST['item_id']?

    You are using it to define the $item_id variable but you're also using it in your for loop with count($_POST['item_id']) which doesn't make sense.
    Chris - Managing Director
    IdleServ Ltd
    IdleServ Web Hosting, Reseller Hosting & Domain Names

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by IdleServ View Post
    What is the contents of $_POST['item_id']?

    You are using it to define the $item_id variable but you're also using it in your for loop with count($_POST['item_id']) which doesn't make sense.
    It is still same like this:

    PHP Code:

         $worker 
    $_POST['worker'];     
         
    $item_id $_POST['item_id'];
         
    $item_name $_POST['item_name'];
         
         for (
    $i=0;$i<=count($item_id);$i++) { 

         
    $query5 mysql_query("UPDATE item SET item_name = '".$item_name[$i]."', worker_id = '".$worker[$i]."' WHERE item_id = '".$item_id[$i]."' ") or die(mysql_error());
         } 
    Do you think there is anything to do with "GROUP BY item_amount"?
    Rapidme
    (rapidshare application)
    www.rapidme.com

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for replies. I changed the codes and it is working now. 1 more question: How can choice a worker select box value can be remembered instead of displaying "Select" value



    PHP Code:

    <?
    include_once ("config/connect.php");
    $ref=$_GET['ref'];

         if (isset(
    $_POST['ok'])) 
    {
         
    $worker $_POST['worker'];     
         
    $item_id $_POST['item_id'];
         
        
         for (
    $i=0;$i<=count($item_id);$i++) { 

         
    $query5 mysql_query("UPDATE item SET worker_id = '".$worker[$i]."' WHERE item_id = '".$item_id[$i]."' ") or die(mysql_error());
         
         }     
             
    }

    ?>



    <table width="100%" border="1" cellpadding="4" cellspacing="4">
    <tr>
        <td><strong>Item</strong></td>
        <td><strong>choice a worker</strong></td>
        <td><strong>chosen worker</strong></td>
      </tr>
      <tr><?php
    $query99 
    "SELECT * FROM item WHERE order_reference_number='$ref' ";
    $portfolio mysql_query($query99);
    while(
    $row109 mysql_fetch_array($portfolio)) {
    ?>
        <td>
        <?=$row109['item_name'];?>
        <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" />
        </td>
        <td>
        <select name="worker[]" id="">
    <option value="Select">Select</option>
    <?php  
    $query3 
    "SELECT * FROM worker";
    $portfolio1 mysql_query($query3);
    while(
    $row3 mysql_fetch_array($portfolio1)) {
    ?>    
    <option><?php echo $row3['worker_name'];?></option>
    <?php ?>
    </select>
     </td>
        <td><?=$row109['worker_id'];?></td>
      </tr><?php
    }
    ?>
    </table>
    Rapidme
    (rapidshare application)
    www.rapidme.com

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your help. One last question

    PHP Code:

     <?php
    $query99 
    "SELECT * FROM item WHERE order_reference_number='$ref'";
    $portfolio mysql_query($query99);
    while(
    $row109 mysql_fetch_array($portfolio)) {
    ?>
    <?=$row109
    ['item_name'];?>
    this is the code. How can I make an if statement that if <?=$row109['item_amount'];?> is bigger than 1 display <?=$row109['item_name'];?> only once.

    Thank you very much
    Rapidme
    (rapidshare application)
    www.rapidme.com

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello,

    This is the last code.

    PHP Code:

    <?
    include_once ("config/connect.php");
    $ref=$_GET['ref'];

    if (isset(
    $_POST['ok'])) 
    {
         
    $worker $_POST['worker'];     
         
    $item_id $_POST['item_id'];
         
        
         for (
    $i=0;$i<=count($item_id);$i++) { 

         
    $query5 mysql_query("UPDATE item SET worker_id = '".$worker[$i]."' WHERE item_id = '".$item_id[$i]."' ") or die(mysql_error());
         
         }     
             
    }

    ?>

    <form action="<?=$PHP_SELF;?>" method="post">
    <table width="600" border="0" cellpadding="4" cellspacing="0" bordercolor="#CCCCCC">

      <tr>
        <td height="24" bgcolor="#999999"><strong>Item amount</strong></td>
        <td height="24" bgcolor="#999999"><strong>Item name</strong></td>
        <td height="24" bgcolor="#999999"><strong>choice a worker</strong></td>
        <td height="24" bgcolor="#999999"><strong>chosen worker</strong></td>
      </tr>
      <tr>
    <?php
    $query99 
    "SELECT * FROM item WHERE order_reference_number='$ref'";
    $portfolio mysql_query($query99);
    $i 0;
    while(
    $row109 mysql_fetch_array($portfolio)) {
    ?>
        
        <td height="32"> &nbsp;&nbsp; <?=$row109['item_amount'];?></td>
        <td height="32"> &nbsp;&nbsp; <?=$row109['item_name'];?>
        <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>
        
        
        <td> &nbsp;&nbsp; 
        <select name="worker[]" id="">
        <option value="<?=$row109['worker_id'];?>"><?=$row109['worker_id'];?></option>
        <option value="-">-</option>

    <?php  
    $query3 
    "SELECT * FROM worker";
    $portfolio1 mysql_query($query3);
    while(
    $row3 mysql_fetch_array($portfolio1)) {
    ?>    
    <option><?php echo $row3['worker_name'];?></option>
    <?php ?>
    </select></td>
        <td> &nbsp;&nbsp; <a href="g">
          <strong><?=$row109['worker_id'];?></strong>
           </a></td>
      </tr><?php
    }
    ?>
    </table>

    <input type="submit" name="ok" value="Submit" onclick="return confirmPost()" />
    </form>
    This is the database:



    This is the output of my code:



    I want to display item_amount and item_name only once if the item_amount is bigger than 1.



    Can somebody help me please.
    Thanks
    Rapidme
    (rapidshare application)
    www.rapidme.com


Bookmarks

Posting Permissions

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