Jump to content

While loop not stopping


Paulqvz

Recommended Posts

I have below script. it does the while loop 100%. it updates the mysql database one at a time as it should. the problem I have now is that the while loop does not end and go to the next statement as it should. it keeps pollong the database. so when in back end you change to 0 it automatically updates again.

Please see if you can help me to see where I can stop this while loop when there are no more loops

// Here I select the amount of rows

$sql_query = "SELECT ae FROM `debitorderrejectionimport` WHERE ae = '0'"; 
$rowCount = mysqli_query($conn,$sql_query); 
$rowCountUpdate = mysqli_num_rows($rowCount); 
echo $rowCountUpdate; 
while($rowCountUpdate > 0)
{ $sql = "UPDATE `ttee`.`au1` 
INNER JOIN `ttee`.`au` ON (`au1`.`id` = `au`.`id`) 
INNER JOIN `ttee`.`ae1` ON (`ae1`.`idd` = `au1`.`idd`) 
INNER JOIN `ttee`.`debitorderrejectionimport` ON (`debitorderrejectionimport`.`nr` = `ae1`.`id`) 
SET `au`.`amount` = `ae1`.`amount` + `au1`.`amount`, `debitorderrejectionimport`.`ae` = au.id ;"; 

$result = mysqli_query($conn, $sql);
$updated = mysqli_affected_rows($conn); 
$rowCountUpdate - ($updated);}

// if it finished updating and there is no more rows it must continue with below query

mysqli_query($conn, " 
INSERT INTO `sataxicrm754`.`debitorderrejectionimport_back` 
( `Outbound`, `Allocation`, `AccountName`, `QueryComplaintType`,
`QueryStatus`, `Querytypeoption`, `Description`, `DealID`, 
`Deals`, `Assignedusername`, `Teams`, `CampaignName`, `CampaignID`, 
`inserted`, `idnumber`, `nr`, `datew`, `premium`, `policynumber`,
`ContactNumber`, `CollectionType`, `OpportunityAmount`, `Broker`, 
`impref`, `id` ) SELECT `Outbound`, `Allocation`, `AccountName`, 
`QueryComplaintType`, `QueryStatus`, `Querytypeoption`, `Description`, 
`DealID`, `Deals`, `Assignedusername`, `Teams`, `CampaignName`, 
`CampaignID`, `inserted`, `idnumber`, `nr`, `datew`, `premium`, 
`policynumber`, `ContactNumber`, `CollectionType`, `OpportunityAmount`, 
`Broker`, `impref`, `id` FROM `sataxicrm754`.`debitorderrejectionimport` 
WHERE QueryComplaintType <> 'QueryComplaintType' ");

 

Link to comment
Share on other sites

You need to change your loop from a while to a for.

for(i=0; i<$rowCountUpdate; i++)

What seems strange to me is that you are not changing your query parameters on each pass. It looks like you are always updating the same row thus the infinite loop.

Edited by gw1500se
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.