freezerburned Posted April 8, 2006 Share Posted April 8, 2006 I'm trying to create a script to delete templates from my database, but I want to make it so that the default template can't be delete (making the checkbox unclickable). [code] while($template = mysql_fetch_array($info)){ $num = count($template['id']) -1; $last = $template['id'][$num]; //if($template['id'][$i] ==0){$disable = "disabled";}else{$disabled = "";} $object[] = "<tr> <td width=50'>{$template['name']}</td> <td width='50'>{$template['id']} Delete: </td> <td><input name='template{$template['id']}' type='checkbox' $disabled value='{$template['id']}'/></td>"; } [/code]Basically I have the code the code ready, but I can't figure out a way of parsing the results so that when it is displayed it outputs all the data correctly. If anyone has any Ideas let me know. I'm up to anything as long as it works. My methods are just what I know. Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 8, 2006 Share Posted April 8, 2006 try this, assuming the default template has id = 1[code]$info = mysql_query("SELECT id, name FROM templates");echo "<FORM method='POST'><TABLE>";while(list($id, $name) = mysql_fetch_row($info)) { $disabled = ($id==1) ? 'disabled' : ''; echo "<tr> <td width=50'>$name</td> <td width='50'>$id</td> <td>Delete: <input name='template[]' type='checkbox' $disabled value='$id'/></td> </tr>"; }echo "</TABLE> <INPUT TYPE='SUBMIT' name='submit' value='Delete selected templates' /> </FORM>";[/code]And to process[code]$del_items = join (',' , $_POST['template']);mysql_query ("DELETE FROM templates WHERE id IN ($del_items)");[/code] 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.