dtdetu Posted December 18, 2008 Share Posted December 18, 2008 hello i use this checkbox code <? $q=mysql_query("select * from iss"); echo " <table border=0 cellspacing=5 width=80%><tr valign=top><td width=33%>"; $i=1; while($r=mysql_fetch_array($q)) { echo "<input type=checkbox name=is[] value=$r[id] >$r[isadi]<br>"; if($i==17) { echo "</td><td width=33%>"; $i=0; } $i++; } echo "</td></tr></table>"; ?> it works but i want to add some kodu to auto check if the post value is checked i used <? $q=mysql_query("select * from iscesitleri"); echo " <table border=0 cellspacing=5 width=80%><tr valign=top><td width=33%>"; $i=1; while($r=mysql_fetch_array($q)) { if($_POST[is][1] == $r[id]) { $checked = "checked"; } echo "<input type=checkbox $checked name=is[] value=$r[id] >$r[isadi]<br>"; if($i==17) { echo "</td><td width=33%>"; $i=0; } $i++; } echo "</td></tr></table>"; ?> but it didnt work can anyone help please Quote Link to comment Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 There are a few BASIC errors in your script and some questions that I have: 1) Never start PHP with "" always use "<?php". 2) Where is your form declared? You need something like this if you want to submit the form to itself. </pre> <form method="POST" action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>">< 3) Show us all the code. 4) So basically you want to generate check boxes via a DB, submit it and remember what was checked after submission? Quote Link to comment Share on other sites More sharing options...
dtdetu Posted December 18, 2008 Author Share Posted December 18, 2008 its a big page i cannot show the all the code , form is a big form too so decleration is at the top of the page, dont ruin my topic if you dont know the answer please you said something none of them are usefull for me Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 18, 2008 Share Posted December 18, 2008 First off Maq was just trying to help you without even seeing much of your code. he is trying to show you the proper methods of php. Basically what I see is wrong is that you did not declare $checked. You need to add this: $checked = ""; above this: echo "<input type=checkbox $checked name=is[] value=$r[id] >$r[isadi]<br>"; and change this: echo "<input type=checkbox $checked name=is[] value=$r[id] >$r[isadi]<br>"; to this: echo "<input type=checkbox checked=$checked name=is[] value=$r[id] >$r[isadi]<br>"; That way it is defined either way. Quote Link to comment Share on other sites More sharing options...
dtdetu Posted December 18, 2008 Author Share Posted December 18, 2008 thank you but now it shows every one of them as checked Quote Link to comment Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 dont ruin my topic if you dont know the answer please you said something none of them are usefull for me It may not be useful to you, but it's useful to me. I don't know how your script works, you're the one who's too inept to write a basic PHP script. So don't worry about me, "ruining" your topic, because I don't like helping ignorant people that are asking for help. Think about how vague your question is but it didnt work can anyone help please You need to learn how to ask a question correctly or no one will be able to help What the hell is "kodu" anyway?! Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 18, 2008 Share Posted December 18, 2008 did you try this? and change this: Code: [select]echo "<input type=checkbox $checked name=is[] value=$r[id] >$r[isadi]<br>"; to this: Code: [select]echo "<input type=checkbox checked=$checked name=is[] value=$r[id] >$r[isadi]<br>"; if so are you getting any errors or what is happening? Quote Link to comment Share on other sites More sharing options...
dtdetu Posted December 18, 2008 Author Share Posted December 18, 2008 did you try this? and change this: Code: [select]echo "<input type=checkbox $checked name=is[] value=$r[id] >$r[isadi]<br>"; to this: Code: [select]echo "<input type=checkbox checked=$checked name=is[] value=$r[id] >$r[isadi]<br>"; if so are you getting any errors or what is happening? yes i tried this now it shows every value as checked Quote Link to comment Share on other sites More sharing options...
dtdetu Posted December 18, 2008 Author Share Posted December 18, 2008 maq get lost and ruin another topic i wont be bothered with you Quote Link to comment Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 maq get lost and ruin another topic i wont be bothered with you Funny how you can't even figure out the solution to a basic PHP technique that I have sitting right in front of me all because you're an ignorant ass. P.S. - Your code is out of date and probably has many security holes and exploits, have fun with that one jerkoff. Quote Link to comment Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 hey idiot Maq its non of your business None of my business? If it's such a secret why are you posting on a public forum...? I think you're the idiot. Besides you're the one in search of answers, I already have them. edit: removed profanity from quote Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 18, 2008 Share Posted December 18, 2008 You really should stop hating on Maq because he is right about alot of things that he has told you and was just trying to be helpful. He is a positive influence on this community I must say myself. If you are going to be a part of this community you must be open to constructive criticism. Anyways this should help: <? $q=mysql_query("select * from iscesitleri"); echo " <table border=0 cellspacing=5 width=80%><tr valign=top><td width=33%>"; $i=1; while($r=mysql_fetch_array($q)) { ?> <input type="checkbox" <?php if($_POST[is][1] == $r[id]){ echo "checked='$checked'"; } ?> name="is[]" value="<?php echo $r[id]; ?>" ><?php echo $r[isadi]; ?><br> <?php if($i==17) { echo "</td><td width=33%>"; $i=0; } $i++; } echo "</td></tr></table>"; ?> I think that should get it going. Please let me know if it works and if you get an error let me know what it is. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 18, 2008 Share Posted December 18, 2008 <?php $query = "select * from iss"; $result = mysql_query($query ); echo "<table border=\"0\" cellspacing=\"5\" width=\"80%\"><tr valign=\"top\">\n"; $records_per_column = ceil(mysql_num_rows($result)/3); $current_record = 1; while($record=mysql_fetch_array($result)) { if ($current_record==1) { echo "<td width=33%>\n"; } $checked = (in_array($record['id'], $_POST['is'])) ? ' checked="checked"' : '' ; echo "<input type=\"checkbox\" name=\"is[]\" value=\"{$record['id']}\"$checked />{$record['isadi']}<br>\n"; $current_record++; if($current_record > $records_per_column) { echo "</td>\n"; $current_record = 1; } } if($current_record != 1) { echo "</td>\n"; } echo "</tr></table>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.