Dynadot โ€” .com Registration $8.99

I need a small help on a query

Spaceship Spaceship
Watch

baris22

Established Member
Impact
1
hello,

My query is not working the way i want. I am trying to do this:

if work_done is "Yes" for all the item_id then SET order_ready to "Yes"
if work_done is "No" for 1 item_id then SET order_ready to "No"

the problem is on second query.

If there is 1 item, my query works. it sets to "Yes" but if there are more than 1 item, my query does not work.

This is my code.
PHP:
for ($i=0;$i<=count($item_id);$i++)  
{ 
       $query = mysql_query("UPDATE item SET worker_id = '".$worker[$i]."', item_done = '".$work_done[$i]."' WHERE item_id = '".$item_id[$i]."' ") or die(mysql_error());
		
       if ($work_done[$i++] == "Yes")  
       {
$query = mysql_query("UPDATE orderr SET order_ready = 'Yes' WHERE order_id = '".$order_id."' ") or die(mysql_error()); 
       }
       else
       {
$query = mysql_query("UPDATE orderr SET order_ready = 'No' WHERE order_id = '".$order_id."' ") or die(mysql_error()); 
       }
       
       
       
}
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
This bit:

PHP:
       if ($work_done[$i++] == "Yes")

increments $i, so skips every other $item_id. You probably want:

PHP:
       if ($work_done[$i] == "Yes")

$order_id is not modified in the loop, so you'll overwrite each modification of the orderr table with the next modification to the orderr table.

What is in the arrays? Could you perhaps give some examples?
 
0
•••
Thanks for help. i am sorted now. i had to do another query

PHP:
if (isset($_POST['ok'])) 
{

$order_id = $_POST['order_id'];
$work_done = $_POST['work_done']; // Yes or No
$worker = $_POST['worker'];  
$item_id = $_POST['item_id'];
$newReference = $_POST['newReference'];


for ($i=0;$i<=count($item_id);$i++)   

{  
       $query = mysql_query("UPDATE item SET worker_id = '".$worker[$i]."', item_done = '".$work_done[$i]."' WHERE item_id = '".$item_id[$i]."' ") or die(mysql_error()); 
 
} 
 
 $query = "SELECT COUNT(*) as num FROM item WHERE order_reference_number = '".$newReference."' AND item_done = 'No' ";
 $total_pages = mysql_fetch_array(mysql_query($query));
 $total_pages = $total_pages[num];
 
 
 if ($total_pages  >= 1)
 
 {
       $query = mysql_query("UPDATE orderr SET order_ready = 'No' WHERE order_id = '".$order_id."' ") or die(mysql_error()); 
 }
        
     else
 
 {
       $query = mysql_query("UPDATE orderr SET order_ready = 'Yes' WHERE order_id = '".$order_id."' ") or die(mysql_error()); 
 }

}
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back