Wrox Programmer Forums
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 1st, 2007, 02:37 PM
Registered User
 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default loop problem

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?

 
Old November 2nd, 2007, 02:15 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

You don't have to execute loop for determining state of database

1) determine total number of rows in $totRowCount

2) execute following query to find whether you new tn exists in database or not.

$rd="SELECT usp_tracking_number,us_id from am_ups_shipment_package_reference WHERE US_TRANKING_NUMBER=" & $TN

if rd->$row_count=0 //tn not found insert multiple times
{
     //insert rows
     for 0 to $totRowCount
        insert rows;
}
else //update
{
      update where traking no = $tn
}

I don't know why you want to insert 4 times or n times, but i hope above algorithm will help you.

urt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Have a problem in For-each loop LeoMathew XSLT 2 July 16th, 2008 05:20 AM
Loop problem! Please help me!! olud ASP.NET 1.0 and 1.1 Basics 2 March 19th, 2007 07:38 AM
problem of infinite loop sarah lee ASP.NET 1.0 and 1.1 Basics 19 December 14th, 2006 09:26 AM
while loop problem shoakat Classic ASP Databases 1 September 21st, 2004 03:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.