Jump to content

Msql Data


freezerburned

Recommended Posts

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']} &nbsp;&nbsp;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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.