473,513 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

explode() problems

tolkienarda
316 Contributor
hi everyone

i am getting a bunch of values from a form via post all of the information that this question deals with is from series of check boxes below is the code that creates the check boxes
the logic behind it is it gets a bunch of listing from the database and if $group is not null then the first check box is checked and a second created else only one unchecked checkbox is created
[PHP]
$result=mysql_query("SELECT TITLE, FNMI, LN, COMPANY, E_MAIL, id, $group FROM DBASE ORDER BY LN");
while($row = mysql_fetch_row($result))
{
if ($row[4] != NULL)
{
if($row[6] != NULL)
{
echo "<input type='checkbox' name='$row[5]' value='$row[5]' checked='checked'>";
echo $row[2], ", ", $row[1], "<input type='checkbox' name='del", $row[5], "' value='$row[5]'><br>\n";
}else{
echo "<input type='checkbox' name='$row[5]' value='$row[5]'>";
echo $row[2], ", ", $row[1], "<br>\n";
}
}
}
[/PHP]

this then goes to the processing script
here i send the $_POST array through a foreach loop getting both the key and the value stored into variables
then i make sure the value is_numeric
then i explode the key to get the 'del' off and store it into the delete array
next i have a sql select statement followed by a loop that walks through all rows of the select
when i am in this loop my $delete array is non existent i've printed it out right below where i make it and it is fine i've even assigned $delete[1] which holds the value i need to a variable and printed that out and it works before the loop but in the loop those variables don't seem to exits
below is that code
[PHP]
foreach($_POST as $key => $value)
{
if(is_numeric($value))
{
$delete = explode("del", $key);
$del = $delete[1];
echo $del;//it is displayed here
$result = mysql_query("SELECT id, $new FROM DBASE WHERE id = $key OR $new IS NOT NULL");

while ($row = mysql_fetch_row($result))
{

if ($row[0] == $key)
{
if ($row[1] == NULL)
{
mysql_query("UPDATE `DBASE` SET `$new` = 'X' WHERE `id` = $key LIMIT 1");
}
}
echo $del; //but not here
if ($row[0] == $del)
{
mysql_query("UPDATE `DBASE` SET `$new` = NULL WHERE `id` = $row[0] LIMIT 1");
}

}
}
}
[/PHP]
for the values where there were two check boxes the values are the same one of the keys has a 'del' in front of it the problem i seem to be having is when i explode the 'del' off the key
May 7 '07 #1
2 2577
ak1dnar
1,584 Recognized Expert Top Contributor
I am not in a sure for these type of line just check the HTML source for this.
[PHP]echo "<input type='checkbox' name='$row[5]' value='$row[5]'>";[/PHP]

it should display like
name= ' valuegoeshere '

Note that single quotes. then how to fetch this form element from next php page.
May 8 '07 #2
Motoma
3,237 Recognized Expert Specialist
It may actually be the case that you are not ever getting inside that while loop, and therefore you are never hit the second echo.

hi everyone

i am getting a bunch of values from a form via post all of the information that this question deals with is from series of check boxes below is the code that creates the check boxes
the logic behind it is it gets a bunch of listing from the database and if $group is not null then the first check box is checked and a second created else only one unchecked checkbox is created
[PHP]
$result=mysql_query("SELECT TITLE, FNMI, LN, COMPANY, E_MAIL, id, $group FROM DBASE ORDER BY LN");
while($row = mysql_fetch_row($result))
{
if ($row[4] != NULL)
{
if($row[6] != NULL)
{
echo "<input type='checkbox' name='$row[5]' value='$row[5]' checked='checked'>";
echo $row[2], ", ", $row[1], "<input type='checkbox' name='del", $row[5], "' value='$row[5]'><br>\n";
}else{
echo "<input type='checkbox' name='$row[5]' value='$row[5]'>";
echo $row[2], ", ", $row[1], "<br>\n";
}
}
}
[/PHP]

this then goes to the processing script
here i send the $_POST array through a foreach loop getting both the key and the value stored into variables
then i make sure the value is_numeric
then i explode the key to get the 'del' off and store it into the delete array
next i have a sql select statement followed by a loop that walks through all rows of the select
when i am in this loop my $delete array is non existent i've printed it out right below where i make it and it is fine i've even assigned $delete[1] which holds the value i need to a variable and printed that out and it works before the loop but in the loop those variables don't seem to exits
below is that code
[PHP]
foreach($_POST as $key => $value)
{
if(is_numeric($value))
{
$delete = explode("del", $key);
$del = $delete[1];
echo $del;//it is displayed here
$result = mysql_query("SELECT id, $new FROM DBASE WHERE id = $key OR $new IS NOT NULL");

while ($row = mysql_fetch_row($result))
{

if ($row[0] == $key)
{
if ($row[1] == NULL)
{
mysql_query("UPDATE `DBASE` SET `$new` = 'X' WHERE `id` = $key LIMIT 1");
}
}
echo $del; //but not here
if ($row[0] == $del)
{
mysql_query("UPDATE `DBASE` SET `$new` = NULL WHERE `id` = $row[0] LIMIT 1");
}

}
}
}
[/PHP]
for the values where there were two check boxes the values are the same one of the keys has a 'del' in front of it the problem i seem to be having is when i explode the 'del' off the key
May 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
5047
by: Rob Gudgeon | last post by:
Hi Is it possible to explode a string into an array using more than one separator? I have database records that contain several values, mostly split by semi-colons but some older records are...
6
23916
by: William Krick | last post by:
I have a string containing concatenated ascii "records" that are each terminated by '\n'. For testing purposes, I construct sample data like this... $mystring =...
12
2891
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
3445
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...
0
1953
by: k04jg02 | last post by:
Python has a nifty operator that will take a container and pass its elements as function parameters. In Python you can make a list like so: x = Then you can say: f(*x)
4
2658
by: Davide | last post by:
Hi All, I'm trying to use explode to separate the result of a textual file, but it explode me only the first row. the foo.txt is pippo pluto pluto pippo pippo pippo .... I use this script...
8
1946
by: Jack | last post by:
I would like to Explode a string into an array that does not begin at 0 but I can't get it to work. For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo = 27 ... $MyInfo = 40...
5
3276
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 =...
8
5456
by: vinpkl | last post by:
hi all i want to use explode url for shotening my urls i have a url like http://localhost/vineet/products.php?dealer_id=12&category_id=2 This is my navigation php code that has url...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7547
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5693
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.