Unstoppable Domains

What is wrong in here?

Spacemail by SpaceshipSpacemail by Spaceship
Watch

baris22

Established Member
Impact
1
Hello all,

I need some help. This is my database:

a.gif


This is the output of my code:

c.gif


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

b.gif


Can you please help me.
Thanks

PHP:
<?
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 } ?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
try putting <= for the count?


PHP:
for ($i=0;$i<=count($_POST['item_id']);$i++) {
 
Last edited:
0
•••
try putting <= for the count?


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

Still same. Do you think there is anything to do with "GROUP BY item_amount"?

Thanks
 
0
•••
I think your count variable is only getting one item_id before the for loop.
 
0
•••
I can't get your code to work.
What are you trying to achieve ?

It seems that your code is not complete. You sometimes expect GET variables, sometimes it's POST and they are not filtered. On a production server this would leave you open to SQL injection attacks.

It's possible that you are updating only one row twice, use echo to spit out the SQL statements that are executed. Also, you have notice errors -
add this on top of your code: error_reporting(E_ALL);

Probably the problem is with the offset in the array:
$item_name = $_POST['item_name']; 2 elements
$worker = $_POST['worker']; 1 element
$item_id = $_POST['item_id']; 2 elements

I suspect that the second SQL statement fails or does nothing.

PHP:
UPDATE item SET item_name = 'Shirt', worker_id = 'Tom' WHERE item_id = '1' 

UPDATE item SET item_name = '', worker_id = 'David' WHERE item_id = ''

If you want to update each row separately I would change the interface a little bit, for example display the 2 rows with a worker combo for each.
 
0
•••
Well, looking at the images and code..

The array of worker[] has elements David, Tom

It seems your UPDATE querey is not reaching 'Tom' in that array at all.

So it is either not there, or your query isnt reaching it.


(This might be exactly the same reasoning as above, sorry if this is)

You are using a loop to create 'Selects' with the same 'name' field.

So you have one select like so:
worker['David']

and then you make a NEW select with the same name and filling as so:
worker['Tom']

This may be clashing, causing you to only recieve the worker['David'] on the other end.

As for a solution to that I dont have the time to solve it right now, someone else might be able to.
 
0
•••
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

5.gif


PHP:
<?
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>
 
0
•••
if you want it to remember whats been chosen before..

you could query to get the current value in the worker column and put this in the first <option> tags instead of it saying Select.

It would result in duplicate entries by simply doing that, but you could do a second query which gets all workers != the worker you just queried for, then use just these as the following ones in the options.

Have a think in regards to something like that.
 
0
•••
Thank you for your help. One last question

PHP:
 <?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
 
0
•••
Could you give a bit more info?

Say you have 4 rows with 'shirt' in the name, they all have an item_amount of 4? If I have understood right.. you could GROUP BY item_name. So that anything with more than 2 in your table will show as just one.

Thought you had that in there already? If you did but it was causing you problems.. then make another sql query and results.. :p

You could write an if statement checking if the item_name has an item_amount > 1, then note down that its already been echo'd so when another one comes along it can check and not print it, but its long and GROUP BY basically does that for you.


PS: why do you have query99? I am sure there are better variable names you can give, like 'query_all_by_ref' so you know what its doing when you use it, same for row109 :p


PPS: You could use DISTINCT in your sql query if you think it does a better job for you: http://www.sql-tutorial.com/sql-distinct-sql-tutorial/
 
Last edited:
0
•••
hello,

This is the last code.

PHP:
<?
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"> ย ย  <?=$row109['item_amount'];?></td>
    <td height="32"> ย ย  <?=$row109['item_name'];?>
	<input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>
    
    
    <td> ย ย  
    <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> ย ย  <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:

1a.gif


This is the output of my code:

1b.gif


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

1c.gif


Can somebody help me please.
Thanks
 
0
•••
Ok... Give this a go, save a backup, written quickly as im rushing out. It probably won't work right but it did in my head :(


PHP:
<?
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' ORDER BY item_name";
$portfolio = mysql_query($query99);
$i = 0;
while($row109 = mysql_fetch_array($portfolio)) {

    if($skip){
    $skipAmount -= 1;
    }else{  ?>
    <td height="32"> ย ย  <?=$row109['item_amount'];?></td>
    <td height="32"> ย ย  <?=$row109['item_name'];?>
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>
   <?php
          if($skipAmount == 0){
          $skip = False;
       }
     }


     if($row109['item_amount']>1){
     $skip = True;
     $skipAmount = $row109['item_amount']-1;
     }
    ?>
    <td> ย ย  
    <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> ย ย  <a href="g">
      <strong><?=$row109['worker_id'];?></strong>
       </a></td>
  </tr><?php
}
?>
</table>

<input type="submit" name="ok" value="Submit" onclick="return confirmPost()" />
</form>
 
0
•••
Thanks alot. Second item is not updating and design is going to left.

2a.gif
 
Last edited:
0
•••
See if this fixes it

PHP:
<?
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' ORDER BY item_name";
$portfolio = mysql_query($query99);
$i = 0;
while($row109 = mysql_fetch_array($portfolio)) {

    if($skip){
    $skipAmount -= 1; ?>
    <td height="32"></td>
    <td height="32">
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>
    
    <?php
    }else{  ?>
    <td height="32"> ย ย  <?=$row109['item_amount'];?></td>
    <td height="32"> ย ย  <?=$row109['item_name'];?>
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>
   <?php
          if($skipAmount == 0){
          $skip = False;
       }
     }


     if($row109['item_amount']>1){
     $skip = True;
     $skipAmount = $row109['item_amount']-1;
     }
    ?>
    <td> ย ย  
    <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> ย ย  <a href="g">
      <strong><?=$row109['worker_id'];?></strong>
       </a></td>
  </tr><?php
}
?>
</table>

<input type="submit" name="ok" value="Submit" onclick="return confirmPost()" />
</form>
 
0
•••
thank you very much . It worked perfect but i realised i made a big mistake on the whole script. I had to add a field on the database. it is called item_ref. Because on the same order i could have same items at the same amount. Like

2- short
1- jeans
2- short

In this case it was messing up. I have got item_ref now which has got same value for same item_amount on each order.

2- short => item_ref = 0001 (this is same for both 2 row)
1- jeans => item_ref = 0002
2- short => item_ref = 0003 (this is same for both 2 row)

Anyway, I think if we can add an if statement like:

if item_ref is equal at item_amount

after

if($row109['item_amount']>1){

it will work perfect. I hope you are with me here.
 
0
•••
PHP:
<?
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' ORDER BY item_name, item_ref";
$portfolio = mysql_query($query99);
$i = 0;
while($row109 = mysql_fetch_array($portfolio)) {

    if($skip){
    $skipAmount -= 1; ?>
    <td height="32"></td>
    <td height="32">
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>
    
    <?php
    }else{  ?>
    <td height="32"> ย ย  <?=$row109['item_amount'];?></td>
    <td height="32"> ย ย  <?=$row109['item_name'];?>
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>
   <?php
          if($skipAmount == 0){
          $skip = False;
          }

     if($row109['item_amount']>1){
     $skip = True;
     $skipAmount = $row109['item_amount']-1;

     }

 }
    ?>
    <td> ย ย  
    <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> ย ย  <a href="g">
      <strong><?=$row109['worker_id'];?></strong>
       </a></td>
  </tr><?php
}
?>
</table>

<input type="submit" name="ok" value="Submit" onclick="return confirmPost()" />
</form>



Give this a go.. its sorted by item_amount and item_ref, so your REF should always be in order too.

I moved the check for >1 inside the main if statement, to prevent issues where u have more than 3 items (my mistake).

See how it works, if it doesnt, can you explain with images like before? makes it easier :wave:
 
0
•••
Hello,

I made some screenshots. This is the current database.

5a.gif


This is the current output of the code:

5b.gif


this is the code:

PHP:
<? 
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%">
<? 
		$query1 = "SELECT * FROM item WHERE order_reference_number='$ref' GROUP BY item_ref";
	    $portfolio = mysql_query($query1);
        while($row1 = mysql_fetch_array($portfolio)) { 
?>
  <tr>
   <td><strong><?=$row1['item_amount'];?> of <?=$row1['item_name'];?></strong></td> 
  </tr>
  <? } ?>
</table>


<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' ORDER BY item_name, item_ref"; 
$portfolio = mysql_query($query99); 
$i = 0; 
while($row109 = mysql_fetch_array($portfolio)) { 

    if($skip){ 
    $skipAmount -= 1; ?> 
    <td height="32"></td> 
    <td height="32"> 
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td> 
     
    <?php 
    }else{  ?> 
    <td height="32"> ย ย  <?=$row109['item_amount'];?></td> 
    <td height="32"> ย ย  <?=$row109['item_name'];?> 
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td> 
   <?php 
          if($skipAmount == 0){ 
          $skip = False; 
          } 

     if($row109['item_amount']>1){ 
     $skip = True; 
     $skipAmount = $row109['item_amount']-1; 

     } 

 } 
    ?> 
    <td> ย ย   
    <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> ย ย  <a href="g"> 
      <strong><?=$row109['worker_id'];?></strong> 
       </a></td> 
  </tr><?php 
} 
?> 
</table> 

<input type="submit" name="ok" value="Submit" onClick="return confirmPost()" /> 
</form>
 
0
•••
PHP:
<? 
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%">
<? 
        $query1 = "SELECT * FROM item WHERE order_reference_number='$ref' GROUP BY item_ref";
        $portfolio = mysql_query($query1);
        while($row1 = mysql_fetch_array($portfolio)) { 
?>
  <tr>
   <td><strong><?=$row1['item_amount'];?> of <?=$row1['item_name'];?></strong></td> 
  </tr>
  <? } ?>
</table>


<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' ORDER BY item_name, item_ref"; 
$portfolio = mysql_query($query99); 
$i = 0; 
while($row109 = mysql_fetch_array($portfolio)) { 
if ($itemRefLast==$row109['item_ref']) { } else {
    if($skip){ 
    $skipAmount -= 1; ?> 
    <td height="32"></td> 
    <td height="32"> 
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td> 
     
    <?php 
    }else{  ?> 
    <td height="32"> ย ย  <?=$row109['item_amount'];?></td> 
    <td height="32"> ย ย  <?=$row109['item_name'];?> 
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td> 
   <?php 
          if($skipAmount == 0){ 
          $skip = False; 
          } 

     if($row109['item_amount']>1){ 
     $skip = True; 
     $skipAmount = $row109['item_amount']-1; 

     } 
  
 } 
    ?> 
    <td> ย ย   
    <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> ย ย  <a href="g"> 
      <strong><?=$row109['worker_id'];?></strong> 
       </a></td> 
  </tr><?php 
    $itemRefLast=$row109['item_ref'];
  } 
}
?> 
</table> 

<input type="submit" name="ok" value="Submit" onClick="return confirmPost()" /> 
</form>


Try that.

Im confusing myself now. I am sure your contradicting what you wanted to display earlier... Now the codes a bit of a mess, it might work, it might not, due to the amount of stuff going on, once it works i am sure you could simplify it so it works the same meeting your needs.. sorry if i cannot be of any more help.
 
0
•••
hello,

Sorry it did not work. Thank you very much for your help.

Current output is:

6a.gif


I am trying to get:

6b.gif


this is the current code:

PHP:
<? 
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%">
<? 
		$query1 = "SELECT * FROM item WHERE order_reference_number='$ref' GROUP BY item_ref";
	    $portfolio = mysql_query($query1);
        while($row1 = mysql_fetch_array($portfolio)) { 
?>
  <tr>
   <td><strong><?=$row1['item_amount'];?> of <?=$row1['item_name'];?></strong></td> 
  </tr>
  <? } ?>
</table>


<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' ORDER BY item_name, item_ref";  
$portfolio = mysql_query($query99);  
$i = 0;  
while($row109 = mysql_fetch_array($portfolio)) {  
if ($itemRefLast==$row109['item_ref']) { } else { 
    if($skip){  
    $skipAmount -= 1; ?>  
    <td height="32"></td>  
    <td height="32">  
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>  
      
    <?php  
    }else{  ?>  
    <td height="32"> ย ย  <?=$row109['item_amount'];?></td>  
    <td height="32"> ย ย  <?=$row109['item_name'];?>  
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>  
   <?php  
          if($skipAmount == 0){  
          $skip = False;  
          }  

     if($row109['item_amount']>1){  
     $skip = True;  
     $skipAmount = $row109['item_amount']-1;  

     }  
   
 }  
    ?>  
    <td> ย ย    
    <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> ย ย  <a href="g">  
      <strong><?=$row109['worker_id'];?></strong>  
       </a></td>  
  </tr><?php  
    $itemRefLast=$row109['item_ref']; 
  }  
} 
?>  
</table>

<input type="submit" name="ok" value="Submit" onClick="return confirmPost()" /> 
</form>
 
0
•••
My fault I think, i was not setting skip to false in the right spot..

give this a try and let me know what the results are.


PHP:
<? 
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%">
<? 
        $query1 = "SELECT * FROM item WHERE order_reference_number='$ref' GROUP BY item_ref";
        $portfolio = mysql_query($query1);
        while($row1 = mysql_fetch_array($portfolio)) { 
?>
  <tr>
   <td><strong><?=$row1['item_amount'];?> of <?=$row1['item_name'];?></strong></td> 
  </tr>
  <? } ?>
</table>


<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' ORDER BY item_name, item_ref";  
$portfolio = mysql_query($query99);  
$i = 0;  
while($row109 = mysql_fetch_array($portfolio)) {  
    if($skip){  
    $skipAmount -= 1; ?>  
    <td height="32"></td>  
    <td height="32">  
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>  
    <?php 
        if($skipAmount == 0){  
          $skip = False;  
        }  
 
    }else{  ?>  
    <td height="32"> ย ย  <?=$row109['item_amount'];?></td>  
    <td height="32"> ย ย  <?=$row109['item_name'];?>  
    <input name="item_id[]" type="hidden" value="<?=$row109['item_id'];?>" /></td>  
   <?php  

     if($row109['item_amount']>1){  
     $skip = True;  
     $skipAmount = $row109['item_amount']-1;  

     }  
   
 }  
    ?>  
    <td> ย ย    
    <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> ย ย  <a href="g">  
      <strong><?=$row109['worker_id'];?></strong>  
       </a></td>  
  </tr><?php  
  
} 
?>  
</table>

<input type="submit" name="ok" value="Submit" onClick="return confirmPost()" /> 
</form>
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back