troubleshooting Question

Moving through a table with gaps

Avatar of steva
steva asked on
PHPMySQL Server
5 Comments1 Solution358 ViewsLast Modified:
I'm wondering what the best way is to move through a  mySql table that has  primary index gaps.  For example, someone may have gone through the table and removed duplicate records, so now the primary index runs 1, 2, 4, 5, 6, 9. . .

I want to do something like below:

for($i=1; $i<=$maxId; $i++) {
	$query = "SELECT email FROM sales WHERE orderID = $i";
	$result = mysqli_query($db, $query) or die ("Couldn't read email from sales table at orderID = $i" . mysqli_error($db));
	$row = mysqli_fetch_assoc($result);
	$email = $row['email'];
             .
                etc. 
	

But I don't want to fall into the "die" hole every time a record is missing.

Thanks for any ideas...

Steve
ASKER CERTIFIED SOLUTION
eriksmtka

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros