Retrieving URL of webpage etc.

Retrieving URL of webpage etc.

am 09.08.2009 09:52:34 von Jacob Kruger

Hi there

I'm specifically doing something like displaying search results up to 50
records, and I would like to be able to provide something like a checkbox
next to each of them to allow multiple records to then be deleted at one
time, but the problem seems to be that either either checkbox needs to be
assigned a different name, or else I would need to be able to parse the URL
of the resulting page when the form is submitted since I don't seem to be
able to access something like an array of values for a form field with the
shared name of the multiple checkboxes, since while it will allow me to read
from an array for the name of that form field:
$_GET['chkBox'][0]

It tells me the count for that array is only 1, and always returns the last
checked value.

Therefore, I could either try use something like javascript to populate a
hidden form field with the various values when the checkboxes are checked,
or else could try just doing something like parsing the querystring/URL
since it does get populated with something like:
chkBox=1&chkBox=2

for example...

Any thoughts on this, and thoughts on what would be the best workaround?

TIA

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4318 (20090808) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Retrieving URL of webpage etc.

am 09.08.2009 10:18:55 von Richard Quadling

2009/8/9 Jacob Kruger :
> Hi there
>
> I'm specifically doing something like displaying search results up to 50
> records, and I would like to be able to provide something like a checkbox
> next to each of them to allow multiple records to then be deleted at one
> time, but the problem seems to be that either either checkbox needs to be
> assigned a different name, or else I would need to be able to parse the URL
> of the resulting page when the form is submitted since I don't seem to be
> able to access something like an array of values for a form field with the
> shared name of the multiple checkboxes, since while it will allow me to read
> from an array for the name of that form field:
> $_GET['chkBox'][0]
>
> It tells me the count for that array is only 1, and always returns the last
> checked value.
>
> Therefore, I could either try use something like javascript to populate a
> hidden form field with the various values when the checkboxes are checked,
> or else could try just doing something like parsing the querystring/URL
> since it does get populated with something like:
> chkBox=1&chkBox=2
>
> for example...
>
> Any thoughts on this, and thoughts on what would be the best workaround?
>
> TIA
>
> Jacob Kruger
> Blind Biker
> Skype: BlindZA
> '...fate had broken his body, but not his spirit...'
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature
> database 4318 (20090808) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Say the ID of the row from the DB is held in $a_Row['ID'].

Make the name of the checkbox ...

name="delete[{$a_Row['ID']}]"

Now, $_POST['delete'] will be an array of IDs to delete.

--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Retrieving URL of webpage etc.

am 09.08.2009 11:45:58 von Jacob Kruger

In this part:
name="delete[{$a_Row['ID']}]"

I presume I would be including that in the echo for the checkbox elements
somehow?

Something along the lines of:
echo '';

Sorry, but haven't really done too much with PHP before apart from simple
things like guestbooks etc.

TIA

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message -----
From: "Richard Quadling"
To: "Jacob Kruger"
Cc:
Sent: Sunday, August 09, 2009 10:18 AM
Subject: Re: [PHP-WIN] Retrieving URL of webpage etc.


> 2009/8/9 Jacob Kruger :
>> Hi there
>>
>> I'm specifically doing something like displaying search results up to 50
>> records, and I would like to be able to provide something like a checkbox
>> next to each of them to allow multiple records to then be deleted at one
>> time, but the problem seems to be that either either checkbox needs to be
>> assigned a different name, or else I would need to be able to parse the
>> URL
>> of the resulting page when the form is submitted since I don't seem to be
>> able to access something like an array of values for a form field with
>> the
>> shared name of the multiple checkboxes, since while it will allow me to
>> read
>> from an array for the name of that form field:
>> $_GET['chkBox'][0]
>>
>> It tells me the count for that array is only 1, and always returns the
>> last
>> checked value.
>>
>> Therefore, I could either try use something like javascript to populate a
>> hidden form field with the various values when the checkboxes are
>> checked,
>> or else could try just doing something like parsing the querystring/URL
>> since it does get populated with something like:
>> chkBox=1&chkBox=2
>>
>> for example...
>>
>> Any thoughts on this, and thoughts on what would be the best workaround?
>>
>> TIA
>>
>> Jacob Kruger
>> Blind Biker
>> Skype: BlindZA
>> '...fate had broken his body, but not his spirit...'
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature
>> database 4318 (20090808) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> Say the ID of the row from the DB is held in $a_Row['ID'].
>
> Make the name of the checkbox ...
>
> name="delete[{$a_Row['ID']}]"
>
> Now, $_POST['delete'] will be an array of IDs to delete.
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
> ZOPA : http://uk.zopa.com/member/RQuadling
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4318 (20090808) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4318 (20090808) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Retrieving URL of webpage etc.

am 10.08.2009 10:24:39 von Richard Quadling

2009/8/10 gunawan :
> answer is near right.. but i have better solution..
> echo ' " />';
> i change into ...
> echo '';
>
> change id into the id you like to delete..
> in delete.php u just type this
>
> foreach($delete as $val)
>   deleteRow($val); //function to delete id in table zz
>
> for your info.. u should not delete the row.. better make them not active
> intead of delete.. if you sure the script aren't have problem.. u can del=
ete
> it.. but remember to backup your DB or ELSE
> *like me.. lost half DB
>
> Jacob Kruger wrote:
>>
>> Hi there
>>
>> I'm specifically doing something like displaying search results up to 50
>> records, and I would like to be able to provide something like a checkbo=
x
>> next to each of them to allow multiple records to then be deleted at one
>> time, but the problem seems to be that either either checkbox needs to b=
e
>> assigned a different name, or else I would need to be able to parse the =
URL
>> of the resulting page when the form is submitted since I don't seem to b=
e
>> able to access something like an array of values for a form field with t=
he
>> shared name of the multiple checkboxes, since while it will allow me to =
read
>> from an array for the name of that form field:
>> $_GET['chkBox'][0]
>>
>> It tells me the count for that array is only 1, and always returns the
>> last checked value.
>>
>> Therefore, I could either try use something like javascript to populate =
a
>> hidden form field with the various values when the checkboxes are checke=
d,
>> or else could try just doing something like parsing the querystring/URL
>> since it does get populated with something like:
>> chkBox=3D1&chkBox=3D2
>>
>> for example...
>>
>> Any thoughts on this, and thoughts on what would be the best workaround?
>>
>> TIA
>>
>> Jacob Kruger
>> Blind Biker
>> Skype: BlindZA
>> '...fate had broken his body, but not his spirit...'
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature database 4318 (20090808) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Whilst "better" is a little subjective, the reason I define the key as
the ID of the array is that I have, in the past, needed different
amounts of information with regard to the data coming back. By using
the key/ID, I can keep all the data in 1 entry.

e.g.

Editing ...

name=3D"data[{$a_Row['ID']}]['name']"
name=3D"data[{$a_Row['ID']}]['date']"
name=3D"data[{$a_Row['ID']}]['email']"

$_POST['data'][123] is the record containing 'name'=3D>'xxxx',
'date'=3D>'yyy', 'email'=3D>'zzz'

sort of thing.

name=3D"data[{$a_Row['ID']}][delete]"

would have been a more appropriate in my usage.



Also, unless you've got a constant called 'id', the output wouldn't be corr=
ect.

echo ' >';


--=20
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
"Standing on the shoulders of some very clever giants!"
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Retrieving URL of webpage etc.

am 10.08.2009 13:14:54 von Jacob Kruger

Ok.

Now got it working with the following two bits of script:
if ($_POST['btnDel'] == "Multiple deletion")
{
// perform multiple delete first
foreach ($_POST as $formField)
checkField($formField);

} // end of delete button pressed

and above that (seems to only see function if located above the call to it):
function checkField($field)
{
$start = substr($field, 0, 5);
if ($start == "doDel")
{
$id = substr($field,5,strLen($field) - 5);
$sql = "delete from article where ID = " . $id . ";";
$result = mysql_query($sql);
} // end of if doDel in string
} // end of function

The checkboxes are generated with the following line of script/code:
echo "";

I initially tried just using either strpos() or stripos() functions to check
if the substring doDel was there, but for some reason it never returned a
result of false no matter what was in the form field's value, so switched
over to the instance of substr() as above.

Will also just now add on some javascript to make the user confirm that they
do in fact want to delete selected records, but anyway...

Thanks for giving me the right ideas with regard to what route to follow,
and I'll just also say that obviously I need to carry on with this stuff a
bit since your examples mostly seemed a bit strange to me with regard to
just including variables etc. inside the string values to be used, which is
why I instead just used what I reckon is a simpler syntax as such.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4321 (20090810) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Retrieving URL of webpage etc.

am 10.08.2009 13:29:50 von Richard Quadling

2009/8/10 Jacob Kruger :
> Ok.
>
> Now got it working with the following two bits of script:
> if ($_POST['btnDel'] == "Multiple deletion")
> {
> // perform multiple delete first
> foreach ($_POST as $formField)
> checkField($formField);
>
> } // end of delete button pressed
>
> and above that (seems to only see function if located above the call to it):
> function checkField($field)
> {
> $start = substr($field, 0, 5);
> if ($start == "doDel")
> {
> $id = substr($field,5,strLen($field) - 5);
> $sql = "delete from article where ID = " . $id . ";";
> $result = mysql_query($sql);
> } // end of if doDel in string
> } // end of function
>
> The checkboxes are generated with the following line of script/code:
> echo "";
>
> I initially tried just using either strpos() or stripos() functions to check
> if the substring doDel was there, but for some reason it never returned a
> result of false no matter what was in the form field's value, so switched
> over to the instance of substr() as above.
>
> Will also just now add on some javascript to make the user confirm that they
> do in fact want to delete selected records, but anyway...
>
> Thanks for giving me the right ideas with regard to what route to follow,
> and I'll just also say that obviously I need to carry on with this stuff a
> bit since your examples mostly seemed a bit strange to me with regard to
> just including variables etc. inside the string values to be used, which is
> why I instead just used what I reckon is a simpler syntax as such.
>
> Stay well
>
> Jacob Kruger
> Blind Biker
> Skype: BlindZA
> '...fate had broken his body, but not his spirit...'
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature
> database 4321 (20090810) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Eek!

echo " value='doDel" . $row['id'] . "' />";

really would be a lot easier on you if use ...

echo " value='doDel" . $row['id'] . "' />";

Now, $_POST['doDel'] is an array you can foreach() on without any need
to decode ...

foreach($_POST['doDel'] as $ID_to_delete => $value_associated_with_input) {
if (intval($ID_to_delete) > 0) {
// Now you can delete based upon the id held in $ID_to_delete.
}
}


--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Retrieving URL of webpage etc.

am 10.08.2009 13:36:44 von Richard Quadling

2009/8/10 Richard Quadling :
> 2009/8/10 Jacob Kruger :
>> Ok.
>>
>> Now got it working with the following two bits of script:
>> if ($_POST['btnDel'] == "Multiple deletion")
>> {
>> // perform multiple delete first
>> foreach ($_POST as $formField)
>> checkField($formField);
>>
>> } // end of delete button pressed
>>
>> and above that (seems to only see function if located above the call to =
it):
>> function checkField($field)
>> {
>> $start =3D substr($field, 0, 5);
>> if ($start == "doDel")
>> {
>> $id =3D substr($field,5,strLen($field) - 5);
>> $sql =3D "delete from article where ID =3D " . $id . ";";
>> $result =3D mysql_query($sql);
>> } // end of if doDel in string
>> } // end of function
>>
>> The checkboxes are generated with the following line of script/code:
>> echo " 'doDel" .
>> $row['id'] . "' />";
>>
>> I initially tried just using either strpos() or stripos() functions to c=
heck
>> if the substring doDel was there, but for some reason it never returned =
a
>> result of false no matter what was in the form field's value, so switche=
d
>> over to the instance of substr() as above.
>>
>> Will also just now add on some javascript to make the user confirm that =
they
>> do in fact want to delete selected records, but anyway...
>>
>> Thanks for giving me the right ideas with regard to what route to follow=
,
>> and I'll just also say that obviously I need to carry on with this stuff=
a
>> bit since your examples mostly seemed a bit strange to me with regard to
>> just including variables etc. inside the string values to be used, which=
is
>> why I instead just used what I reckon is a simpler syntax as such.
>>
>> Stay well
>>
>> Jacob Kruger
>> Blind Biker
>> Skype: BlindZA
>> '...fate had broken his body, but not his spirit...'
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus signa=
ture
>> database 4321 (20090810) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> Eek!
>
> echo " > value=3D'doDel" . $row['id'] . "' />";
>
> really would be a lot easier on you if use ...
>
> echo " > value=3D'doDel" . $row['id'] . "' />";
>
> Now, $_POST['doDel'] is an array you can foreach() on without any need
> to decode ...
>
> foreach($_POST['doDel'] as $ID_to_delete =3D> $value_associated_with_inpu=
t) {
>  if (intval($ID_to_delete) > 0) {
>  // Now you can delete based upon the id held in $ID_to_delete.
>  }
> }
>
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D2134=
74731
> "Standing on the shoulders of some very clever giants!"
> ZOPA : http://uk.zopa.com/member/RQuadling
>

If you want to take a look at the heredoc [1] and nowdoc [2]
documentation, you may find that these are a LOT easier to work with
than trying to quote ' and " appropriately.

e.g.

echo <<< END_INPUT
id']}" />
END_INPUT;

for example.

Regards,

Richard Quadling.

[1] http://docs.php.net/manual/en/language.types.string.php#lang uage.types.=
string.syntax.heredoc
[2] http://docs.php.net/manual/en/language.types.string.php#lang uage.types.=
string.syntax.nowdoc

--=20
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
"Standing on the shoulders of some very clever giants!"
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Retrieving URL of webpage etc.

am 10.08.2009 15:14:28 von Jacob Kruger

Ok, will try out that one.

Basically you're saying that the PHP backend will automatically make those
checkboxes into an array if I implement that syntax?

There is really only one other form field on that page - a search textbox -
apart from the possible 50 checkbox fields, but will definitely look into
it.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message -----
From: "Richard Quadling"
To: "Jacob Kruger"
Cc:
Sent: Monday, August 10, 2009 1:29 PM
Subject: Re: [PHP-WIN] Retrieving URL of webpage etc.


> 2009/8/10 Jacob Kruger :
>> Ok.
>>
>> Now got it working with the following two bits of script:
>> if ($_POST['btnDel'] == "Multiple deletion")
>> {
>> // perform multiple delete first
>> foreach ($_POST as $formField)
>> checkField($formField);
>>
>> } // end of delete button pressed
>>
>> and above that (seems to only see function if located above the call to
>> it):
>> function checkField($field)
>> {
>> $start = substr($field, 0, 5);
>> if ($start == "doDel")
>> {
>> $id = substr($field,5,strLen($field) - 5);
>> $sql = "delete from article where ID = " . $id . ";";
>> $result = mysql_query($sql);
>> } // end of if doDel in string
>> } // end of function
>>
>> The checkboxes are generated with the following line of script/code:
>> echo "";
>>
>> I initially tried just using either strpos() or stripos() functions to
>> check
>> if the substring doDel was there, but for some reason it never returned a
>> result of false no matter what was in the form field's value, so switched
>> over to the instance of substr() as above.
>>
>> Will also just now add on some javascript to make the user confirm that
>> they
>> do in fact want to delete selected records, but anyway...
>>
>> Thanks for giving me the right ideas with regard to what route to follow,
>> and I'll just also say that obviously I need to carry on with this stuff
>> a
>> bit since your examples mostly seemed a bit strange to me with regard to
>> just including variables etc. inside the string values to be used, which
>> is
>> why I instead just used what I reckon is a simpler syntax as such.
>>
>> Stay well
>>
>> Jacob Kruger
>> Blind Biker
>> Skype: BlindZA
>> '...fate had broken his body, but not his spirit...'
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature
>> database 4321 (20090810) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> Eek!
>
> echo " > value='doDel" . $row['id'] . "' />";
>
> really would be a lot easier on you if use ...
>
> echo " > value='doDel" . $row['id'] . "' />";
>
> Now, $_POST['doDel'] is an array you can foreach() on without any need
> to decode ...
>
> foreach($_POST['doDel'] as $ID_to_delete => $value_associated_with_input)
> {
> if (intval($ID_to_delete) > 0) {
> // Now you can delete based upon the id held in $ID_to_delete.
> }
> }
>
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
> ZOPA : http://uk.zopa.com/member/RQuadling
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4321 (20090810) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4321 (20090810) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Retrieving URL of webpage etc.

am 10.08.2009 19:07:34 von bedul

answer is near right.. but i have better solution..
echo '';
i change into ...
echo '';

change id into the id you like to delete..
in delete.php u just type this

foreach($delete as $val)
deleteRow($val); //function to delete id in table zz

for your info.. u should not delete the row.. better make them not
active intead of delete.. if you sure the script aren't have problem.. u
can delete it.. but remember to backup your DB or ELSE
*like me.. lost half DB

Jacob Kruger wrote:
> Hi there
>
> I'm specifically doing something like displaying search results up to
> 50 records, and I would like to be able to provide something like a
> checkbox next to each of them to allow multiple records to then be
> deleted at one time, but the problem seems to be that either either
> checkbox needs to be assigned a different name, or else I would need
> to be able to parse the URL of the resulting page when the form is
> submitted since I don't seem to be able to access something like an
> array of values for a form field with the shared name of the multiple
> checkboxes, since while it will allow me to read from an array for the
> name of that form field:
> $_GET['chkBox'][0]
>
> It tells me the count for that array is only 1, and always returns the
> last checked value.
>
> Therefore, I could either try use something like javascript to
> populate a hidden form field with the various values when the
> checkboxes are checked, or else could try just doing something like
> parsing the querystring/URL since it does get populated with something
> like:
> chkBox=1&chkBox=2
>
> for example...
>
> Any thoughts on this, and thoughts on what would be the best workaround?
>
> TIA
>
> Jacob Kruger
> Blind Biker
> Skype: BlindZA
> '...fate had broken his body, but not his spirit...'
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4318 (20090808) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php