smilesmita Posted November 1, 2007 Share Posted November 1, 2007 there is this Db table Tracking number description 36 XYZ 46 abc 98 lmn i have this loop in my php file: $tn=tracking number/numbers received in a file $rd = $db->Query("SELECT usp_tracking_number,us_id from am_ups_shipment_package_reference"); for ( $i = 0; $rd && $i < $rd->Row_Count(); $i++ ) { $tuple = $rd->Fetch_Row($i); if ($tuple["Tracking Number"]==$tn){ update the tables with the new data associated with that tracking number } else{ insert the new record } } wht is happening: if the new tracking number provided in the fils is 98 then 98!=36 insert record 96 in the table 98!=46 insert record 96 in the table 98=98 update wht is wanted is: 98 is compared against 3 and found that its alaredy present and shud just get updated. Also if a totally new tn is given..for example 33 it doesnt match with any tracking number and gets inserted 4 times. any idea wht i am missing? Quote Link to comment https://forums.phpfreaks.com/topic/75676-loop-problem/ Share on other sites More sharing options...
Daukan Posted November 1, 2007 Share Posted November 1, 2007 $tuple["Tracking Number"] should be $tuple[0] since fetch_row retrieves with a numbered index. Make sure all variables are set. Place error_reporting(0); at the beginning of your script. Quote Link to comment https://forums.phpfreaks.com/topic/75676-loop-problem/#findComment-383020 Share on other sites More sharing options...
kratsg Posted November 1, 2007 Share Posted November 1, 2007 Can you get all the different tracking numbers as an array? If so, use the following if(in_array($number_to_check,$array_of_tracking_numbers)){//it was found, so just update //update } else {//it was not found, so we add /add } Quote Link to comment https://forums.phpfreaks.com/topic/75676-loop-problem/#findComment-383024 Share on other sites More sharing options...
teng84 Posted November 1, 2007 Share Posted November 1, 2007 weird for ( $i = 0;[b] $rd && $i < $rd->Row_Count()[/b]; $i++ ) { Quote Link to comment https://forums.phpfreaks.com/topic/75676-loop-problem/#findComment-383067 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.