Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

I need a small help on a query

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
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
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back