Jump to content


Msql Data

  • Please log in to reply
1 reply to this topic

#1 freezerburned

  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 08 April 2006 - 03:38 AM

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).
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>";

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.


#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 08 April 2006 - 10:12 AM

try this, assuming the default template has id = 1
$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>

echo "</TABLE>
        <INPUT TYPE='SUBMIT'  name='submit' value='Delete selected templates' />

And to process

$del_items = join (',' , $_POST['template']);

mysql_query ("DELETE FROM templates WHERE id IN ($del_items)");

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users