By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

list and explode

P: n/a
Hello,

I have been searching for a reason for this behavior but no solution
so I figured I would ask.

Basically I have a web page that displays data in a database to the
user for updates/deletion/addition. For each data field ont he web
page I put the data from the database in the field name with teh field
name and data seperated by a |. ex: address|35 Elm St.

I then loop thru all the fields on the form and if the data in the
field name doesnt match the data submitted then update the database.
Here is the code:

foreach ($_REQUEST as $curFld => $Data) {
if ($curFld <> 'Submit') {
list ($field, $orig_data, $table, $id) = explode('|', $curFld);

if ($orig_data <> $_POST[$curFld]) {
//UPDATE DATABASE
$sql = "UPDATE $table SET $field = '".$_POST[$curFld]."' WHERE
ID = $id";
$result = mysql_query($sql, $_SESSION['conn']) or
die(mysql_error());
}
}
}

Here is the problem, either list() or explode() is replacing all
spaces in $orig_data with underscores so 35 Elm St. becomes
35_Elm_St.. This causes the code to always update this field and any
others where this occurs. Obviously I could do this str_replace("_",
" ", $orig)data) to fix this problem but if the user wants to use
underscores I dont want to replace them. (Address is not the only
field on the page.

Thanks in advance.

Mark
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
why not just update all teh data, changed or not?
"Mark" <ma********@myrapidsys.com> wrote in message
news:58**************************@posting.google.c om...
Hello,

I have been searching for a reason for this behavior but no solution
so I figured I would ask.

Basically I have a web page that displays data in a database to the
user for updates/deletion/addition. For each data field ont he web
page I put the data from the database in the field name with teh field
name and data seperated by a |. ex: address|35 Elm St.

I then loop thru all the fields on the form and if the data in the
field name doesnt match the data submitted then update the database.
Here is the code:

foreach ($_REQUEST as $curFld => $Data) {
if ($curFld <> 'Submit') {
list ($field, $orig_data, $table, $id) = explode('|', $curFld);

if ($orig_data <> $_POST[$curFld]) {
//UPDATE DATABASE
$sql = "UPDATE $table SET $field = '".$_POST[$curFld]."' WHERE
ID = $id";
$result = mysql_query($sql, $_SESSION['conn']) or
die(mysql_error());
}
}
}

Here is the problem, either list() or explode() is replacing all
spaces in $orig_data with underscores so 35 Elm St. becomes
35_Elm_St.. This causes the code to always update this field and any
others where this occurs. Obviously I could do this str_replace("_",
" ", $orig)data) to fix this problem but if the user wants to use
underscores I dont want to replace them. (Address is not the only
field on the page.

Thanks in advance.

Mark

Jul 17 '05 #2

P: n/a
"Mark" <ma********@myrapidsys.com> wrote in message
news:58**************************@posting.google.c om...
Hello,

I have been searching for a reason for this behavior but no solution
so I figured I would ask.

Basically I have a web page that displays data in a database to the
user for updates/deletion/addition. For each data field ont he web
page I put the data from the database in the field name with teh field
name and data seperated by a |. ex: address|35 Elm St.


You have a race hazard the size of Texas, man. Just update all the fields.
Jul 17 '05 #3

P: n/a
I am currently doing that and in less than one day we had more than
900,000 updates to the database. So I would like to avoid any
uneccessary updates.

"Alexander Ross" <al******@bleen.net> wrote in message news:<nWifc.142603$K91.356452@attbi_s02>...
why not just update all teh data, changed or not?
"Mark" <ma********@myrapidsys.com> wrote in message
news:58**************************@posting.google.c om...
Hello,

I have been searching for a reason for this behavior but no solution
so I figured I would ask.

Basically I have a web page that displays data in a database to the
user for updates/deletion/addition. For each data field ont he web
page I put the data from the database in the field name with teh field
name and data seperated by a |. ex: address|35 Elm St.

I then loop thru all the fields on the form and if the data in the
field name doesnt match the data submitted then update the database.
Here is the code:

foreach ($_REQUEST as $curFld => $Data) {
if ($curFld <> 'Submit') {
list ($field, $orig_data, $table, $id) = explode('|', $curFld);

if ($orig_data <> $_POST[$curFld]) {
//UPDATE DATABASE
$sql = "UPDATE $table SET $field = '".$_POST[$curFld]."' WHERE
ID = $id";
$result = mysql_query($sql, $_SESSION['conn']) or
die(mysql_error());
}
}
}

Here is the problem, either list() or explode() is replacing all
spaces in $orig_data with underscores so 35 Elm St. becomes
35_Elm_St.. This causes the code to always update this field and any
others where this occurs. Obviously I could do this str_replace("_",
" ", $orig)data) to fix this problem but if the user wants to use
underscores I dont want to replace them. (Address is not the only
field on the page.

Thanks in advance.

Mark

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.