seeking check box auto selecting advice
i have a bunch of check boxes on a control panel. right now i print out what the previous selections were by catagory and only update the ones with new seelctions.
what i want is to modify this so that i can run the print out using the info i get from the db (broken by catagory). so i have a few lists of interests from a greater set in each catagory.
the number of interests (select boxes and titles) displayed per row changes by catagory.
once i echo out the page i don't want to go in and out of php. right now i use heredocs to make the page.
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 00:21 — 11th August 2003.
He has: 4,048 posts
Joined: Aug 2000
Do you have code we can see?
I'm assuming your using a loop, but I have no idea how you're identifying your pre-selected checkboxes.
<?php
while ($checkbox=mysql_fetch_thingy($result)) {
echo \"<input type=\\"checkbox\\" \".($checkbox==$selected?'CHECKED':'').\" />\n\";
}
?>
Mark Hensler
If there is no answer on Google, then there is no question.
Suzanne posted this at 00:31 — 11th August 2003.
She has: 5,507 posts
Joined: Feb 2000
*noting more efficient coding*
If you're using XHTML, you'll need to report:
checked="checked" or selected="selected" (for select options), not just checked or selected. Just FYI.
Suzanne posted this at 00:44 — 11th August 2003.
She has: 5,507 posts
Joined: Feb 2000
<?php
// for use with the echo<<<VAR type of printing
$pprimary_checked = ($form_phone_primary == 'y'?'checked=\"checked\" ':'' );
$ppublic_checked = ($form_phone_public == 'y'?'checked=\"checked\" ':'' );
echo<<<VAR
<input name=\"phone_primary\" value=\"$pid\" type=\"radio\" $pprimary_checked/><br />
<input name=\"phone[$pid][public]\" value=\"y\" type=\"checkbox\" $ppublic_checked/>\n
VAR;
?>
Is there a more efficient way to do this? Obviously there is a chunk of code missing, this is just the part with the checked notation.
Mark Hensler posted this at 00:55 — 11th August 2003.
He has: 4,048 posts
Joined: Aug 2000
In this case, I would avoid using the heredoc syntax. I used to do the exact same thing, but I've changed my opinion on the matter as I now thing it will be slower. This is because you have two extra assignment opperations. (Not that this is some great overhead, but I'm always trying to up my coding standards and habbits)
*moan*
Mark Hensler
If there is no answer on Google, then there is no question.
Suzanne posted this at 01:30 — 11th August 2003.
She has: 5,507 posts
Joined: Feb 2000
I have the two variables set and then use them all over. Is that less of a burden or more?
I guess part of it is a balance between modularization and efficiency?
For some reason I can never remember heredoc as a name. echo<<<, I remember. Heredoc, nope.
Sorry about the bad news of the XHTML coding, lol.
Mark Hensler posted this at 05:30 — 11th August 2003.
He has: 4,048 posts
Joined: Aug 2000
The speed will be the same, but you'll save memory by reusing the same variables. If you had a huge echo statement, I could see heredoc (echo<<<) being a resonable choice, and in that case, you'd have to use variables.
Something else I've been curious about is are there any speed/load differences (on a very minute scale) between a normal echo() call, and an echo heredoc call (echo<<<). Seems like it would take longer for the interpreter to parse for the heredoc delimiter than it would take for it to handle a quoted string. I've never read any comparison.
Mark Hensler
If there is no answer on Google, then there is no question.
m3rajk posted this at 16:48 — 11th August 2003.
They have: 461 posts
Joined: Jul 2003
i'm trying to use html 4.01 (transitional) here, which i think will let me go either way
i should still alter the select box stuff.
currently the part of the function that prints out the select boxes in the control panel looks like this (some returns included to stop scrrolling):
<?php
function interest(){ # in interests
include(\"/home/joshua/includes/fyd.vars.php\"); # includes file (precautionary measure)
$result; $selections;
$un=$_COOKIE['un']; $pw=$_COOKIE['pw']; # variables to talk to the db
$db=mysql_pconnect('host', 'login', pw) or die(\"cannot access db\"); # connect to the db
$fyd=mysql_select_db('findyourdesire', $db); # get the db
$memfind=mysql_query(\"SELECT * FROM users WHERE username=$un\", $db);
if(mysql_num_rows($memfind)==0){ # problem
echo '<h1>We cannot find you. Are you sure you <a href=\\"join.php\\">Joined?</a>';
}else{ # we found the user
$maininf=mysql_fetch_array($memfind);
$pwc=$maininf['password'];
if($pw!=$pwc){ # cannot verify user
echo \"<p>Cannot verify that you are $un.
Password error (submitted pw does not match file)</p></center></body></html>\";
}else{ # we know who we're dealin with
$uin=$maininf['uid']; $intToUp=''; $selections='';
if(isset($_POST['act'])) { # update the db
# get the submitted information about the interests
$smusic=$_POST['music']; $sbooks=$_POST['books']; $smovies=$_POST['movies'];
$ssports=$_POST['sports']; $smisc=$_POST['misc']; $spets=$_POST['pets'];
# turn the submitted interests (sinterests) array into strings
$movies=join(' ',$smovies); $books=join(' ',$sbooks); $misc=join(' ',$smisc);
$sports=join(' ',$ssports); $music=join(' ',$smusic); $pets=join(' ',$spets);
# clean the lists incase someone did do something to screw with the input
$movies=clean($movies); $books=clean($books); $misc=clean($misc);
$sports=clean($sports);
$music=clean($music); $pets=clean($pets);
if($movies!=''){ $intToUp=$intToUp.\"movies=$movies\"; } # get the update list
if($books!=''){ if($intToUp!=''){ $intToUp=$intToUp.', '; }
$intToUp=$intToUp.\"books=$books\"; }
if($music!=''){ if($intToUp!=''){ $intToUp=$intToUp.', '; }
$intToUp=$intToUp.\"music=$music\"; }
if($pets!=''){ if($intToUp!=''){ $intToUp=$intToUp.', '; }
$intToUp=$intToUp.\"pets=$pets\"; }
if($sports!=''){ if($intToUp!=''){ $intToUp=$intToUp.', '; }
$intToUp=$intToUp.\"sports=$sports\"; }
if($misc!=''){ if($intToUp!=''){ $intToUp=$intToUp.', '; }
$intToUp=$intToUp.\"misc=$misc\"; }
$update=mysql_query(\"UPDATE interests SET $intToUp WHERE uid=$uin\", $db);
if(mysql_affected_rows($db)==1){ $result='Update Successful'; }
else{ $result='Error on update. Please try again.'; }
} # done with the possible update, retrieve info and display
$interestfind=mysql_query(\"SELECT * FROM interests WHERE uid=$uin\", $db);
if(mysql_num_rows($interestfind)==0){ # error
exit(\"<h1>Database failure. Please alert the administration.
While your Main Info is on Record, your Interests information has disappeared</h1>\");
}else{ # we got the info
$interests=mysql_fetch_array($interestfind);
$selections='<br />Movies:'.$interests['movies'].'
<br />Books:'.$interests['books'].'<br />Music:'.$interests['music'].
'<br />Pets:'.$interests['pets'].'<br />Sports:'.$interests['sports'].
'<br />Misc:'..$interests['misc'];
}
# make the page
echo <<<END
<p>$result</p>
<p>Your Current Selections (updating only affect changed groups.
only the new selections will be in the update): $selections</p>
<form action=\"$_SERVER[PHP_SELF]\" method=\"POST\">
<input type=\"hidden\" name=\"fn\" value=\"interest\"><input type=\"hidden\"
name=\"act\" value=\"process\">
<table frame=\"void\" bgcolor=\"#000000\" text=\"#c8c8c8\" border=\"0\"
cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td colspan=\"2\" align=\"center\"><!-- inner table for interest: music -->
<table frame=\"box\" bgcolor=\"#000000\" border=\"1\" cellpadding=\"0\"
cellspacing=\"0\" text=\"#c8c8c8\" width=\"100%\">
<tr><th colspan=\"7\">Please check off all Genres of Music that
interest you</th></tr>
<tr><td><input type=\"checkbox\" name=\"music[]\" value=\"Blues\">
Blues</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Christian\">
Christian</td><td><input type=\"checkbox\" name=\"music[]\" value=\"classical\">
Classical</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Country-Western\">
Country/Western</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Dance\">
Dance</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Folk\"> Folk</td>
<td><input type=\"checkbox\" name=\"music[]\" value=\"Gospell\"> Gospel</td></tr>
<tr><td><input type=\"checkbox\" name=\"music[]\" value=\"Jazz\">
Jazz</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Opera\">
Opera</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Other\">
Other</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Polka\">
Polka</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Pop\">
Pop</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Rap\">
Rap</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Rock\"> Rock</td></tr>
<tr><td><input type=\"checkbox\" name=\"music[]\" value=\"Salsa\">
Salsa</td><td><input type=\"checkbox\" name=\"music[]\" value=\"Techno\">
Techno</td><td> </td><td> </td><td> </td><td> </td><td>
</td></tr>
</table>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"><!-- inner table for interest: Movies -->
<table frame=\"box\" bgcolor=\"#000000\" border=\"1\" cellpadding=\"0\"
cellspacing=\"0\" text=\"#c8c8c8\" width=\"100%\">
<tr><th colspan=\"6\">Please check off all Genres of Movies that
interest you</th></tr>
<tr><td><input type=\"checkbox\" name=\"movies[]\" value=\"Action\">
Action</td><td><input type=\"checkbox\" name=\"movies[]\" value=\"Animated\">
Animated</td><td><input type=\"checkbox\" name=\"movies[]\" value=\"Comedy\">
Comedy</td><td><input type=\"checkbox\" name=\"movies[]\" value=\"Childrens\">
Children's (Disney)<!-- ' (to fool xemacs) --></td>
<td><input type=\"checkbox\" name=\"movies[]\" value=\"Documentary\"> Documentary</td>
<td><input type=\"checkbox\" name=\"movies[]\" value=\"Drama\"> Drama</td></tr>
<tr><td><input type=\"checkbox\" name=\"movies[]\" value=\"Fantasy\">
Fantasy</td><td><input type=\"checkbox\" name=\"movies[]\" value=\"Foreign\">
Foreign</td><td><input type=\"checkbox\" name=\"movies[]\" value=\"Horror\">
Horror</td><td><input type=\"checkbox\" name=\"movies[]\" value=\"Other\">
Other</td><td><input type=\"checkbox\" name=\"movies[]\" value=\"Romance\">
Romance</td><td><input type=\"checkbox\" name=\"movies[]\" value=\"Science-Fiction\">
Science-Fiction</td></tr>
</table>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"><!-- inner table for interest: Books -->
<table frame=\"box\" bgcolor=\"#000000\" border=\"1\" cellpadding=\"0\"
cellspacing=\"0\" text=\"#c8c8c8\" width=\"100%\">
<tr><th colspan=\"7\" >Please check off all Genres of Books that
interest you</th></tr>
<tr><td><input type=\"checkbox\" name=\"books[]\" value=\"Comedy\">
Comedy</td><td><input type=\"checkbox\" name=\"books[]\" value=\"Comic\"> Comic</td>
<td><input type=\"checkbox\" name=\"books[]\" value=\"Fantasy\"> Fantasy</td>
<td><input type=\"checkbox\" name=\"books[]\" value=\"Other\"> Other</td>
<td><input type=\"checkbox\" name=\"books[]\" value=\"Horror\"> Horror</td>
<td><input type=\"checkbox\" name=\"books[]\" value=\"Mystery\"> Mystery</td>
<td><input type=\"checkbox\" name=\"books[]\" value=\"Romance\"> Romance</td></tr>
<tr><td><input type=\"checkbox\" name=\"books[]\" value=\"Science-Fiction\">
Science-Fiction</td><td> </td><td> </td><td> </td><td> </td>
<td> </td><td> </td></tr>
</table>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"> <!-- inner table for interest: Sports-->
<table frame=\"box\" bgcolor=\"#000000\" border=\"1\" cellpadding=\"0\"
cellspacing=\"0\" text=\"#c8c8c8\" width=\"100%\">
<tr><th colspan=\"7\">Please check off all Sports that interest
you</th></tr>
<tr><td><input type=\"checkbox\" name=\"sports[]\" value=\"Baseball\">
Baseball</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Basketball\">
Basketball</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Curling\">
Curling</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Dance\">
Dance</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Fencing\">
Fencing</td></tr>
<tr><td><input type=\"checkbox\" name=\"sports[]\" value=\"Field-Hockey\">
Field Hockey</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Fishing\">
Fishing</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Football\">
Football</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Gymnastics\">
Gymnastics</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Hockey\">
Hockey</td></tr>
<tr><td><input type=\"checkbox\" name=\"sports[]\" value=\"Ice-Skating\">
Ice Skating</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Inline-Skating\">
Inline Skating</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Luge\">
Luge</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Other\"> Other</td>
<td><input type=\"checkbox\" name=\"sports[]\" value=\"Skate-Boarding\"> Skate Boarding</td>
</tr>
<tr><td><input type=\"checkbox\" name=\"sports[]\" value=\"Sky-Diving\">
Sky Diving</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Snow-Boarding\">
Snow Boarding</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Street-Luge\">
Street Luge</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Surfing\">
Surfing</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Swimming\">
Swimming</td></tr>
<tr><td><input type=\"checkbox\" name=\"sports[]\" value=\"Track-Field\">
Track & Field</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Tennis\">
Tennis</td><td><input type=\"checkbox\" name=\"sports[]\" value=\"Volleyball\">
Volleyball</td><td> </td><td> </td></tr>
</table>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"> <!-- inner table for interest: Pets-->
<table frame=\"box\" bgcolor=\"#000000\" border=\"1\" cellpadding=\"0\"
cellspacing=\"0\" text=\"#c8c8c8\" width=\"100%\">
<tr><th colspan=\"7\">Please check off all Pets that interest you</th>
</tr>
<tr><td><input type=\"checkbox\" name=\"pets[]\" value=\"Birds\">
Birds</td><td><input type=\"checkbox\" name=\"pets[]\" value=\"Cats\"> Cats</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Dogs\"> Dogs</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Fish\"> Fish</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Gerbils\"> Gerbils</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Hamsters\"> Hamsters</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Hermit-Crabs\"> Hermit Crabs</td></tr>
<tr><td><input type=\"checkbox\" name=\"pets[]\" value=\"Horses\">
Horses</td><td><input type=\"checkbox\" name=\"pets[]\" value=\"Lizards\">
Lizards</td><td><input type=\"checkbox\" name=\"pets[]\" value=\"Mice\"> Mice</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Other\"> Other</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Rabbits\"> Rabbits</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Rats\"> Rats</td>
<td><input type=\"checkbox\" name=\"pets[]\" value=\"Snakes\"> Snakes</td></tr>
</table>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\"> <!-- inner table for interest: Misc-->
<table frame=\"box\" bgcolor=\"#000000\" border=\"1\" cellpadding=\"0\"
cellspacing=\"0\" text=\"#c8c8c8\" width=\"100%\">
<tr><th colspan=\"4\">Please check off all Miscellaneous Interests
that interest you</th></tr>
<tr><td><input type=\"checkbox\" name=\"misc[]\" value=\"Aircraft-C\">
Aircraft (Commercial)</td
<td><input type=\"checkbox\" name=\"misc[]\" value=\"Aircraft-M\"> Aircraft (Military)</td>
<td><input type=\"checkbox\" name=\"misc[]\" value=\"Cars-Trucks\"> Cars/Trucks</td>
<td><input type=\"checkbox\" name=\"misc[]\" value=\"Computers-G\"> Computer Games</td></tr>
<tr><td><input type=\"checkbox\" name=\"misc[]\" value=\"Computers-H\">
Computer Hardware</td><td><input type=\"checkbox\" name=\"misc[]\" value=\"Computer-P\">
Computer Programming</td><td><input type=\"checkbox\" name=\"misc[]\" value=\"Occult\">
Occult</td><td><input type=\"checkbox\" name=\"misc[]\" value=\"Other\">
Other</td></tr>
<tr><td><input type=\"checkbox\" name=\"misc[]\" value=\"Religions\">
Religions</td><td><input type=\"checkbox\" name=\"misc[]\" value=\"RPG\">
Role Playing Games (RPGs)</td><td> </td><td> </td></tr>
</table>
</td>
</tr>
<tr>
<td align=\"center\"><input type=\"submit\" value=\"Update Interests\"></td>
<td align=\"center\"><input type=\"reset\" value=\"Nah, Nothing's Changed\"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
END;
}
}
}
?>
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 20:32 — 11th August 2003.
He has: 4,048 posts
Joined: Aug 2000
Not tested.
And I also changed formating to the PEAR Coding Standards.
<?php
function interest()
{
// includes file (precautionary measure)
include(\"/home/joshua/includes/fyd.vars.php\");
$result;
$selections;
// variables to talk to the db
$un = $_COOKIE['un'];
$pw = $_COOKIE['pw'];
$db = mysql_pconnect('host', 'login', pw) or die(\"cannot access db\");
$fyd = mysql_select_db('findyourdesire', $db);
$memfind = mysql_query(\"SELECT * FROM users WHERE username=$un\", $db);
if (mysql_num_rows($memfind)==0){ // problem
echo '<h1>We cannot find you. Are you sure you <a href=\\"join.php\\">Joined?</a>';
return;
}
$maininf = mysql_fetch_array($memfind);
$pwc = $maininf['password'];
if ($pw!=$pwc){
// cannot verify user
echo \"<p>Cannot verify that you are $un. \"
.\"Password error (submitted pw does not match file)</p></center></body></html>\";
return;
}
$uin = $maininf['uid'];
$intToUp = '';
$selections = '';
if (isset($_POST['act'])) {
// update the db
// get the submitted information about the interests
$smusic = $_POST['music'];
$sbooks = $_POST['books'];
$smovies = $_POST['movies'];
$ssports = $_POST['sports'];
$smisc = $_POST['misc'];
$spets = $_POST['pets'];
// turn the submitted interests (sinterests) array into strings
$movies = join(' ', $smovies);
$books = join(' ', $sbooks);
$misc = join(' ', $smisc);
$sports = join(' ' ,$ssports);
$music = join(' ', $smusic);
$pets = join(' ', $spets);
// clean the lists incase someone did do something to screw with the input
$movies = clean($movies);
$books = clean($books);
$misc = clean($misc);
$sports = clean($sports);
$music = clean($music);
$pets = clean($pets);
// get the update list
$intToUp = '';
$intToUp .= 'movies='.($movies!='' && $intToUp!='' ? \", $movies\" : '');
$intToUp .= 'books='.($books!='' && $intToUp!='' ? \", $books\" : '');
$intToUp .= 'music='.($music!='' && $intToUp!='' ? \", $music\" : '');
$intToUp .= 'pets='.($pets!='' && $intToUp!='' ? \", $pets\" : '');
$intToUp .= 'sports='.($sports!='' && $intToUp!='' ? \", $sports\" : '');
$intToUp .= 'misc='.($misc!='' && $intToUp!='' ? \", $misc\" : '');
$update = mysql_query(\"UPDATE interests SET $intToUp WHERE uid=$uin\", $db);
if (mysql_affected_rows($db)==1) {
$result='Update Successful';
}
else {
$result='Error on update. Please try again.';
}
} //END if (isset($_POST['act']))
// done with the possible update, retrieve info and display
$interestfind = mysql_query(\"SELECT * FROM interests WHERE uid=$uin\", $db);
if (mysql_num_rows($interestfind)==0) {
// error!
exit(\"<h1>Database failure. Please alert the administration.\"
.\"While your Main Info is on Record, your Interests information has disappeared</h1>\");
}
$interests = mysql_fetch_array($interestfind);
$selections = '<br />Movies:'.$interests['movies'].'<br />'
.'Books:'.$interests['books'].'<br />'
.'Music:'.$interests['music'].'<br />'
.'Pets:'.$interests['pets'].'<br />'
.'Sports:'.$interests['sports'].'<br />'
.'Misc:'.$interests['misc'];
// hard-coded interest array
$arr_interests = array(
'musics' => array(
'blues' => 'Blues',
'christian' => 'Christian',
'classical' => 'Classical',
'country-western' => 'Country/Western',
'dance' => 'Dance',
'Folk' => 'Folk',
'gospell' => 'Gospell',
'jazz' => 'Jazz',
'opera' => 'Opera',
'other' => 'Other',
'polka' => 'Polka',
'pop' => 'Pop',
'rap' => 'Rap',
'rock' => 'Rock',
'salsa' => 'Salsa',
'techno' => 'Techno',
),
'movies' => array(
'action' => 'Action',
'animated' => 'Animated',
'comedy' => 'Comedy',
'childrens' => 'Childrens',
'documentary' => 'Documentary',
'drama' => 'Drama',
'fantasy' => 'Fantasy',
'foreign' => 'Foreign',
'horror' => 'Horror',
'other' => 'Other',
'romance' => 'Romance',
'science-fiction' => 'Science-Fiction'
),
'books' => array(
'comedy' => 'Comedy',
'comic' => 'Comic',
'horror' => 'Horror',
'mystery' => 'Mystery',
'other' => 'Other',
'romance' => 'Romance',
'science-fiction' => 'Science-Fiction'
),
'sports' => array(
'baseball' => 'Baseball',
'basketball' => 'Basketball',
'curling' => 'Curling',
'dance' => 'Dance',
'fencing' => 'Fencing',
'field-hockey' => 'Field Hockey',
'fishing' => 'Fishing',
'football' => 'Football',
'gymnastics' => 'Gymnastics',
'hockey' => 'Hockey',
'ice-skating' => 'Ice Skating',
'inline-skating' => 'Inline Skating',
'luge' => 'Luge',
'other' => 'Other',
'skate-boarding' => 'Skate Boarding',
'sky-diving' => 'Sky Diving',
'snow-boarding' => 'Snow Boarding',
'street-luge' => 'Street Luge',
'surfing' => 'Surfing',
'swimming' => 'Swimming',
'track-field' => 'Track & Field',
'tennis' => 'Tennis',
'volleyball' => 'Volleyball'
),
'pets' => array(
'birds' => 'Birds',
'cats' => 'Cats',
'dogs' => 'Dogs',
'fish' => 'Fish',
'gerbils' => 'Gerbils',
'hamsters' => 'Hamsters',
'hermit-crabs' => 'Hermit Crabs',
'horses' => 'Horses',
'lizards' => 'Lizards',
'mice' => 'Mice',
'other' => 'Other',
'rabbits' => 'Rabbits',
'rats' => 'Rats',
'Snakes' => 'Snakes'
),
'misc' => array(
'aircraft-c' => 'Aircraft (Commercial)',
'aircraft-m' => 'Aircraft (Military)',
'cars-trucks' => 'Cars/Trucks',
'computers-g' => 'Computer Games',
'computers-h' => 'Computer Hardware',
'computers-p' => 'Computer Programming',
'occult' => 'Occult',
'other' => 'Other',
'oeligions' => 'Religions',
'rpg' => 'Role Playing Games (RPGs)'
)
);
// make the page
echo <<<END
<p>$result</p>
<p>Your Current Selections (updating only affect changed groups.
only the new selections will be in the update): $selections</p>
<form action=\"$_SERVER[PHP_SELF]\" method=\"POST\">
<input type=\"hidden\" name=\"fn\" value=\"interest\">
<input type=\"hidden\" name=\"act\" value=\"process\">
<table frame=\"void\" bgcolor=\"#000000\" text=\"#c8c8c8\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr><td colspan=\"2\" align=\"center\">
END;
$col = 7;
foreach ($arr_interests as $topic=>$array) {
echo \"<tr>\n\";
echo \" <td colspan=\\"2\\" align=\\"center\\">\n\";
echo \"\n\";
echo \"<table frame=\\"box\\" bgcolor=\\"#000000\\" border=\\"1\\" cellpadding=\\"0\\"\"
.\" cellspacing=\\"0\\" text=\\"#c8c8c8\\" width=\\"100%\\">\n\";
echo \"<tr><th colspan=\\"7\\">Please check off everything that interests you</th></tr>\n\";
$i=0;
foreach ($array as $key=$val) {
if ($i==0) echo \"<tr>\n\";
echo \" <td><input type=\\"checkbox\\" name=\\"\".$topic.\"[]\\" value=\\"$key\\" \"
.(in_array(${'s'.$topic}, $key) ? 'checked=\"checked\"' : '')
.\" /> $val</td>\n\";
if ($i==$col) {
echo \"</tr>\n\";
$i=0;
}
}
if ($i!=0) {
// finish of the row
for ($i; $i<$col; $i++) {
echo \" <td> </td>\n\";
}
echo \"</tr>\n\";
}
echo \"</table>\n\";
echo \"\n\";
echo \" </td>\n\";
echo \"</tr>\n\";
}
echo <<<END
</form>
</center>
</body>
</html>
END;
} //END function interest()
?>
Mark Hensler
If there is no answer on Google, then there is no question.
Suzanne posted this at 22:05 — 11th August 2003.
She has: 5,507 posts
Joined: Feb 2000
Those arrays seem really weird to me. Why repeat it all? For display purposes only?
Mark Hensler posted this at 01:34 — 12th August 2003.
He has: 4,048 posts
Joined: Aug 2000
Repeat what? You mean "key"=>"var" ? I did this so that the name of the input may be different from the description. Generally, I like to keep my input names lower case.
This should also prevent duplicates. Consider this:
$tmp = array('this' => 'that', 'here' => 'there', 'this' => 'those')
$tmp['this'] should now be 'those'.
Mark Hensler
If there is no answer on Google, then there is no question.
m3rajk posted this at 01:36 — 12th August 2003.
They have: 461 posts
Joined: Jul 2003
i want to remove the part where i list out what they previously selected, and have them populated so they can update it that wayit would be easier for the user
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.