Page 1 of 1
somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 10:37 am
by glennn.php
wow, where do i start...
http://thecodedepot.com/HFPjobs1/post.php - posting checkbox arrays (Specialty, Subspec. and Region) to the database is not a problem. the script implodes() the values attached to each checkbox into something like "1 5 9 10 11" and writes to one field, then explodes() these values back to their given Names based on a table in the db: db.categories.id('#') and db.categories.name('Name') ...
the problem is, all this work is done by several functions in a remote file - i also need to take the array and simply echo each value as its name in the Preview page - getting the single Posted values to another page isn't a problem, but i'm having trouble getting the checkboxes selected echoed in a second page. need your help.
keep in mind that these values are stored in tables as .id and .name fields, so i can call them from the db according to the form checkboxes selected (i figure i kinda have to since the values of the checkboxes are "1", "2" etc...). perhaps not, this is over my head.
could someone kindly show me what i can do to achieve this, or tell me i'm not making any sense...?
Many Thanks
GN
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 11:08 am
by aceconcepts
So what you want to do is have each checkbox correctly "checked" according to the db values?
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 11:21 am
by glennn.php
no - i knew i complicated it more... : o )
simply put, i have this:
Code: Select all
<input name="category[]" type="checkbox" value="1" /> Anatomic (AP)
<input name="category[]" type="checkbox" value="2" /> Anatomic & Clinical(AP/CP)
<input name="category[]" type="checkbox" value="3" /> Cardiovascular Pathology
<input name="category[]" type="checkbox" value="4" /> Cytopathology
<input name="category[]" type="checkbox" value="5" /> Dermatopathology
and i'd like to echo only the selected value NAMES (Anatomic, Cytopathology, etc...) in a second page...
i knew i should have just said it that way.
Love Twain, by the way.
GN
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 12:32 pm
by aceconcepts
Ok I get it now.
So what you do id:
Code: Select all
if(isset($_POST['submit']))
{
//GET THE CHECKBOXES
$category=$_POST['category'] //this is passed as an array
//CHECK WHETHER A CHECKBOX HAS BEEN SELECTED
if(empty($category))
{
//LOOP THE SELECTED CATEGORIES
for($x=0; $x<count($category); $x++)
{
echo $category[$x] . '<br />'; //output each selected category
}
}
}
I hope this makes sense to you
I love Twain
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 12:49 pm
by glennn.php
Parse error: syntax error, unexpected T_IF in /.../prev_post.php at 102 >>
if(empty($category))
{

(
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 12:51 pm
by aceconcepts
Sorry, it's been a long day at work.
Code: Select all
if(isset($_POST['submit']))
{
//GET THE CHECKBOXES
$category=$_POST['category']; //this is passed as an array
//CHECK WHETHER A CHECKBOX HAS BEEN SELECTED
if(!empty($category))
{
//LOOP THE SELECTED CATEGORIES
for($x=0; $x<count($category); $x++)
{
echo $category[$x] . '<br />'; //output each selected category
}
}
}
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 12:58 pm
by glennn.php
it returned nothing - i'm sending this post with a javascript (have to - 2 buttons...):
document.form.action = "prev_post.php"
document.form.target = "_blank";
would that change things...?
if(isset($_POST['submit'])) isn't... ?
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 1:03 pm
by aceconcepts
Take out the submit clause then:
Code: Select all
//GET THE CHECKBOXES
$category=$_POST['category']; //this is passed as an array
//CHECK WHETHER A CHECKBOX HAS BEEN SELECTED
if(!empty($category))
{
//LOOP THE SELECTED CATEGORIES
for($x=0; $x<count($category); $x++)
{
echo $category[$x] . '<br />'; //output each selected category
}
}
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 1:51 pm
by glennn.php
awesome, yes -
last annoyance:
somewhere in there i have to convert the value="2" (etc) to "Anatomic & Clinical" (etc)... i can't change the values of the checkboxes from the int to the name because of how it's written to the db and then returned...
i apologize; this is how i've learned everything i know, which isn't much. i've yet to learn nomenclature ('clause', 'method'...) which has severely inhibited my learning. best i can do is find scripts that do what i need and edit them (i can read the stuff, just can't write it).
This thing has gone on way too long and i just need this to finish it and get on with my life. :o)
I really do appreciate your help. after this i'll send you MY favorite Twain quote. you're not French, i hope...
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 2:04 pm
by aceconcepts
No i'm not French - I'm English, from London.
Anyway, The following method is rather adhoc and there is probably a better way of doing it.
However, here goes:
Code: Select all
//change the value of the element to:
<input name="category[]" type="checkbox" value="1-Anatomic" /> Anatomic (AP)
//do the same for the others - no spaces before or after "-"
And then change the code i posted to:
Code: Select all
//GET THE CHECKBOXES
$category=$_POST['category']; //this is passed as an array
//CHECK WHETHER A CHECKBOX HAS BEEN SELECTED
if(!empty($category))
{
//LOOP THE SELECTED CATEGORIES
for($x=0; $x<count($category); $x++)
{
$exp=explode("-", $category[$x]);
//$exp[0] is the int, and $exp[1] is the name
echo $exp[0] . ' - ' . $exp[1] . '<br />'; //output each selected category
}
}
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 2:27 pm
by glennn.php
well, if you're english then you'll love everything MT had to say about the French.
i can't change the values of the checkboxes - the INSERT function implodes the values to a string and writes them to a single field in the db (2 5 9 11 12) and then calls these and explodes them back to their names - well, i guess i could - i could just remove the '-Anatomic' before the script parses it...?
sorry - won't take up any more of your time. thanks for all your help.
Twain -
"A French married lady cannot enter even a menagerie without bringing the purity of that menagerie under suspicion."
"The average American may not know who his grandfather was. But the American was, however, one degree better off than the average Frenchman who, as a rule, was in considerable doubt as to who his father was."
"You can tell German wine from vinegar by the label."
http://www.twainquotes.com/French.html
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 2:33 pm
by glennn.php
beautiful - worked well - i can get them parsed back to ints myself. thanks for your help.
Re: somewhat complex Posting, Implode and Explode issues
Posted: Thu Apr 24, 2008 2:35 pm
by aceconcepts
I'm glad i could help.
MT is simply superb.
Thanks fro the quotes
