Jump to content

trying to count in while loop query


jakebur01

Recommended Posts

Basically, this part of the code is checking the "scanned" table in my mysql database to get the last scanned date for the item at hand.  It then takes that date and selects all the vendor items in the odbc table "ARVEND" that are greater than the last purchase date.  || This is where I am running into a problem.  When it loops through each vendor item it selects from the "associated" mysql table to see if the vendor item has been scanned.  If it does not find anything I am trying to get the $checkpurdate variable to add 1 to itself. |

 

In the second script you will see the elseif($checkpurdate>0) .... Here I am saying if there are any vendor items that have not been scanned, highlight the row in yellow.

 

But, this part of my code $checkpurdate = $checkpurdate + 1; does not seem to be counting correctly.  Sometimes it counts '4' for an item when there are only two vendor items available.

 

All of this may sound confusing since you may not know what I am trying to do.  But, the main problem I am having is the counting part is returning wrong numbers. $checkpurdate = $checkpurdate + 1;

 

 

/* $checkpurdate  */

$query3  = "SELECT date FROM scanned WHERE `item` = '$ITEM' ORDER BY date DESC LIMIT 1";
$result3 = mysql_query($query3);
$checklastdate = "";
 while($row3 = mysql_fetch_array($result3, MYSQL_ASSOC))
{$checklastdate= $row3['date'];
$checklastdate=date("m/d/y", strtotime($checklastdate));   }

//checkpurdate loops
$checkassoc="0";
$checkpurdate="0";
$sqlc="SELECT RECNO5 FROM ARVEND WHERE PURDATE1 > '$checklastdate' AND ITEM = '$ITEM'";
$rsc=odbc_exec($conn,$sqlc);
if (!$rsc)
  {exit("Error in SQL");}
  
while (odbc_fetch_row($rsc))
  {
  $checkrecno5=odbc_result($rsc,"RECNO5");
$checkassosquery  = "associated WHERE `VENDORID` = '$checkrecno5' AND ITEM = '$ITEM'";
$checkassoc = get_rows($checkassosquery);
  
  if($checkassoc>0)
  { 
  // do nothing
  }
  else 
  { 
  $checkpurdate = $checkpurdate + 1;
  }
  

}

 

  elseif($checkpurdate>0)
{  echo"<TR class=\"NV\"> <TD>";	
}

 

Link to comment
Share on other sites

I think in this odbc query the select where the purchase date is greater that the scan date is not working.  Here is an example of one row: Scan date=03/21/11 Purchase date=09/07/06. SELECT PURDATE1, RECNO5 FROM ARVEND WHERE PURDATE1 > '03/21/11' AND ITEM = '0270' AND PURDATE1 <> ''

 

Query:

SELECT PURDATE1, RECNO5 FROM ARVEND WHERE PURDATE1 > '$checklastdate' AND ITEM = '$ITEM' AND PURDATE1 <> ''

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.