somewhat complex Posting, Implode and Explode issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

somewhat complex Posting, Implode and Explode issues

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: somewhat complex Posting, Implode and Explode issues

Post by aceconcepts »

So what you want to do is have each checkbox correctly "checked" according to the db values?
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

Re: somewhat complex Posting, Implode and Explode issues

Post 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" />&nbsp;Anatomic (AP)
<input name="category[]" type="checkbox" value="2" />&nbsp;Anatomic & Clinical(AP/CP) 
<input name="category[]" type="checkbox" value="3" />&nbsp;Cardiovascular Pathology
<input name="category[]" type="checkbox" value="4" />&nbsp;Cytopathology
<input name="category[]" type="checkbox" value="5" />&nbsp;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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: somewhat complex Posting, Implode and Explode issues

Post 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 :D

I love Twain
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

Re: somewhat complex Posting, Implode and Explode issues

Post by glennn.php »

Parse error: syntax error, unexpected T_IF in /.../prev_post.php at 102 >>

if(empty($category))
{

:o(
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: somewhat complex Posting, Implode and Explode issues

Post 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
         }
   }
}
 
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

Re: somewhat complex Posting, Implode and Explode issues

Post 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... ?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: somewhat complex Posting, Implode and Explode issues

Post 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
         }
   }
 
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

Re: somewhat complex Posting, Implode and Explode issues

Post 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...
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: somewhat complex Posting, Implode and Explode issues

Post 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" />&nbsp;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
         }
   }
 
Last edited by aceconcepts on Thu Apr 24, 2008 2:06 pm, edited 1 time in total.
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

Re: somewhat complex Posting, Implode and Explode issues

Post 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
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

Re: somewhat complex Posting, Implode and Explode issues

Post by glennn.php »

beautiful - worked well - i can get them parsed back to ints myself. thanks for your help.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: somewhat complex Posting, Implode and Explode issues

Post by aceconcepts »

I'm glad i could help.

MT is simply superb.

Thanks fro the quotes :D
Post Reply