Jump to content

Anomalous DB fields; echo discrepancy


Lienne

Recommended Posts

Hi all,

So I'm getting some strange results from one of my scripts. I have an MSSQL DB which has a list of peoples' addresses. I need to do some other processing to the data, so I decided to assign each person a "counter" (basic ID). In comes the troubling script. Bascially, the script iterates through every row in the DB and assigns it a number one higher than the last row. Very simple. But for some reason, it's not working exactly properly. The echo that I put in the script shows everything working perfectly fine. But for some reason, in the DB itself sometimes the numbers are not correct. For instance, one time through it looked like this:
1
2
3
351
5
...
And the crazy thing is that there was no 4. Nowhere. Another time, there were 2 4's. This problem seems to be randomly scattered throughout the rows with various incorrect numbers.

So does anyone know why there would be an inconsistency between the echo output and what is actually put in the DB? I'm quite stumped on this one....help!


[code]<?
include("includes/db.inc.php");

$counter = 0; //init counter

$master_results = mssql_query("SELECT * FROM contacts_temp WHERE deleted='1' AND id=''"); //get resident results
$master_numrows = mssql_num_rows($master_results);

for ($i=0; $i<$master_numrows; $i++) {
$master_row = mssql_fetch_array($master_results);
$street_name = $master_row['street_name'];
$prefix_directional = $master_row['prefix_directional'];
$street_suffix = $master_row['street_suffix'];
$post_directional = $master_row['post_directional'];
$house_number = $master_row['house_number'];

$master_results2 = mssql_query("UPDATE contacts_temp SET counter=$counter WHERE deleted='1' AND id='' AND street_name='$street_name' AND prefix_directional='$prefix_directional' AND street_suffix='$street_suffix' AND post_directional='$post_directional' AND house_number='$house_number'");
echo $counter . "<br>";
$counter++;
}

?>[/code]
Link to comment
Share on other sites

I tried echoing the SQL statement, and it looks fine. For some reason though, the database still has some problems. For instance, there are two row 8 and no row 7. But the output looks like:

[code]6: UPDATE contacts_temp SET counter=6 WHERE deleted='1' AND id='' AND street_name='ALABAMA' AND prefix_directional=' ' AND street_suffix=' ' AND post_directional=' ' AND house_number='2105'
7: UPDATE contacts_temp SET counter=7 WHERE deleted='1' AND id='' AND street_name='ALABAMA' AND prefix_directional=' ' AND street_suffix=' ' AND post_directional=' ' AND house_number='2109'
8: UPDATE contacts_temp SET counter=8 WHERE deleted='1' AND id='' AND street_name='ALABAMA' AND prefix_directional=' ' AND street_suffix=' ' AND post_directional=' ' AND house_number='2109'[/code]
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.