473,385 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

list and explode

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
3 2891
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Craig Keightley | last post by:
is it possible to compare acomma separated list aginst another eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match??? the...
1
by: Craig Keightley | last post by:
I can do the match perfectly but what i also need to do is create a third list of comma separated values that are in both eg: List 1 => 1,2,3,4,5,6,7,8,11 List 2 => 1,3,4,5,6,7,10,23 ...
4
by: blrmaani | last post by:
Here is what I want: string s1 = "This is a list of string"; list<string> s2 = s1.some_method(); Now, I should be able to traverse list s2 and get each member ( which is of type 'string' ). ...
12
by: frizzle | last post by:
Hi there, i have a site with fake folders & files. htaccess rewrites everything to index.php?vars now in index.php i decide what file to include with a switch/case statement. to define where...
5
by: FFMG | last post by:
Hi, I need the php equivalent of explode in one of my app. I read a very big file and "explode" each line to fill a structure. The reading of the file, 19Mb, (I will also need to streamline...
6
by: oskar | last post by:
Hello everyone. I have a problem with my program... and i kinda dunno what to do.. everything seems to work ok, but i'm getting corrupted double-linked list error =\. *** glibc detected ***...
2
by: Kirkingly | last post by:
I want to create the following print_r results into a dynamic select list.. I have tried something like: <?php $prefixes = array(explode("\n", $board)); echo '<select name="tprefix">';...
5
by: sathyashrayan | last post by:
Dear group, The function to be used as follows: $links = "http://www.campaignindia.in/feature/analysis"; $tag1 = '<div class=feature-wrapper>'; $tag2 = '<h1><a href'; $tag3 = "</a>"; $op =...
7
by: Michael Sharman | last post by:
Is there a PHP function which can add single quotes around each item in a list? So if I have: $myList = "michael,frank,peter,sally,june"; What I want to end up with is: $myList =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.