Zend - The PHP Company




Databases

Add Code


Delete  

Type: code fragment
Added by: RLYNCH
Entered: 13/02/2000
Last modified: 08/12/1999
Rating: *** (10 votes)
Views: 13890
A very brief sample of how to delete items from a database.


<?php
    $connection 
pg_connect('host=localhost user=www password=www dbname=goner') or die("Could not connect to goner");
  if (isset(
$goners)){
    while (list(
$id) = each($goners)){
      
$query "delete from contacts where id = $id";
      
pg_exec($connection$query) or die($query);
    }
  }
  
$query "select id, name from contacts";
  
$results pg_exec($connection$query) or die($query);
  echo 
"<FORM ACTION=goner.php METHOD=POST>n";
  
$contactCount 0;
  while (list(
$id$name) = @pg_fetch_row($results$contactCount)){
    echo 
"<INPUT TYPE=CHECKBOX NAME=goners[$id]> $name<BR>n";
    
$contactCount++;
  }
  echo 
"<INPUT TYPE=SUBMIT>n";
  echo 
"</FORM>n";
 
/*
SQL to build sample database named 'goner'
drop table contacts;
drop sequence contactID;

create sequence contactID;
create table contacts(
  id int4 default nextval('contactID'),
  name text
);

grant all on contacts to www;

insert into contacts(name) values('Rasmus Lerdorf');
insert into contacts(name) values('Zeev Suraski');
insert into contacts(name) values('Andi Gutmans');
insert into contacts(name) values('Linus Torvalds');
 */
?>


Usage Example




Rate This Script





Search



This Category All Categories