Creating a loop to update DB IDs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Creating a loop to update DB IDs

Post by impulse() »

I have a DB with a log file of all connections entering my website. From testing on this I have ran 'php <file>' from a console which has caused blank entries in the table and then genuine data has been added and I've now deleted these blank lines which has left a bad increment of the IDs eg - 1, 2, 3, 5, 6, 7.
What function is there in PHP to edit data on a certain row in the database and not where certain data is equal to something on any row. I want to go though:

A) Update row 1 ID with <variable>
B) Update row 2 ID with <variable + 1>
etc etc

I can do the looping I just don't know how to select certain rows.

Can someone point me in the right direction please.

Regards, Stephen
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A select query with a WHERE clause.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

How do I do a WHERE rownumber = $i?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You don't. Either use specifics for that row or store the results that would select all of the records you want to iterate over into an array before processing.
Post Reply