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
https://forums.phpfreaks.com/topic/6858-msql-data/
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
https://forums.phpfreaks.com/topic/6858-msql-data/#findComment-24986
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.