Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Deleting Database Rows From An Array Of Variables


I have a form with a list of checkboxes, which are each filled with a date in the format 27012007, for example. The name of each of the checkboxes is the same as the date.

Basically when the user presses the submit button I would like all rows in the database table "users" with the corresponding column "date" to be deleted when the form variables date correspond to those in the "date" rows. I think all the checked dates might also need to be put into an array. Would anyone know how to do this?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Checking If A Value Is Not In An Array And Deleting Record From Database
I have been trying to figure this one out and have come up against a brick wall although I know it should be relatively simple. I have a form that passes an array to a php script from a multiple select box that is created dynamically.  If a user deselects an item then I want to delete the record from the database but am having a big problem with it. The table in the dbase is quite simple with just three fields:

id
classid
formid

Basically, the form send through a classid and a formid value and I want to delete any records that have a classid that are not in the form array and have a formid which is passed as a hidden value. I suppose really what I want is to know how to see if a classid is not in the array that is passed.

Deleting Rows In Mysql
Is there a way in php that I can mark a row in my mysql database and then later so delete these rows that have been marked?

Deleting Mutiple Rows
I have this Code:

echo "<td>";
echo "<input type='checkbox' name='id' value='";
echo $row["id"];
echo "'></td>";
etc etc etc ect....

The above code works for 1 record at a time. I can't change the name of the form field to del[] cause I need that id in there.

Autoincrement - After Deleting Rows -
If I delete rows in my database via phpadmin, it remembers which row ID had previously been used, so the remaining records are 1, 3, 4, 5, 8   and the rows I deleted  (2, 6, 7) no longer exist.  Is there some means of having the database forget the dropped records, so the numbering is sequential?

Deleting Blank Rows
I have some rows in my mysql table that have blank fields as part numbers. I want to delete all of the rows that have blank part numbers.

would it be like:

delete from table where partnumber = '0';

Deleting Mysql Rows
Is there an easy or another way to delete rows? Right now I'm checkmarking the row I want to delete and then clicking on the red x for each one. It takes absolutely forever. Is there a better way?

Deleting Rows Across Multiple Tables
Using MySQL. Documentation is not clear to me, and it remains clear after doing some searching.

I know this does NOT work

DELETE FROM table1,table2,table3,table4 WHERE dataID='id'

Do I really need to run 4 queries? Seems awfully inefficient.

Mysql And Php5 Deleting Rows
I can't seem to delete rows from a mysql database. I have a database
that I want to delete rows from based on user name. i have researched
this extensively and can't seem to find anything that works.

Deleting Rows On Text File
I have a function where it writes data on a text file with an assigned id. For example, the text file looks like:

data.txt

1|Hey
45|Hi
76|Hello

What I'd like to do is add a function that will allow me to use the specific line that start with the id. For example:

delete.php : On this file I will pass the id number and based on it, the function will go to the data.txt file and delete the specific row. So if I pass the id=45, it will remove that row ONLY and the data.txt file will look like below after removal:

1|Hey
76|Hello

Deleting Multiple Checked Rows With Foreach()
I'm trying to delete multiple entries from a mysql table using the following script:
variables are passed using: PHP Code:

Selecting Array Rows Based On An Array Of Field=>values
Here's the code i have:

$db = array(); //main array
$db['main'] = array(); //table `main`
$db['main'][] = array('id'=>0,
'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin');
//row
$db['main'][] = array('id'=>1,
'username'=>'bob_smith','userpass'=>'psswrd','userlevel'=>'user');
//row

function trim_value(&$value){
$value = strtolower(trim($value));
}
function fdb_select($fields = "*", $table, $where = false, $limit =
false){
global $db;
$retv = $db[$table];

//LIMIT RESULTS TO FIELDS
if(strrpos($fields, ",") === false){$field=array($fields);}else{$field
= explode(",", $fields);};
array_walk($field, "trim_value");
$all_fields = array_keys($retv[0]);
if($fields == '*'|| is_null($fields)){$field = $all_fields;};
$field = array_uintersect($all_fields, $field, "strcasecmp");
$retvi = array();
foreach($retv as $num =$row){
foreach($row as $fname =$fvalue){
$fname1 = strtolower($fname);
if(in_array($fname1, $field)){
$retvi[$num][$fname]=$fvalue;
};
};
};
//DONE LIMITING TO FIELDS
if($where != false){

//UP TO HERE IT WORKS FINE
//LIMIT TO WHERE CLAUSE
$retvj = array();
foreach($retvi as $num =$row){
//IN THE ROW
foreach($where as $k =$v){
//IF ROW MEETS ALL REQUIREMENTS
if($row[$k] == $v){
$retvj[] = $retvi[$num]; //Keep that row
};
};
};
//DONE LIMITING TO WHERE CLAUSE
};
$retvi = (isset($retvj)) ? $retvj:$retvi;
//SEND A FINAL ASSOCIATIVE ARRAY
return $retvi;
};
print_r(fdb_select("*", "main", array('id'=>"1",
"username"=>"joshfrench")));

the previous code outputs this:

Array
(
[0] =Array
(
[id] =0
[username] =joshfrench
[userpass] =password
[userlevel] =admin
)

[1] =Array
(
[id] =1
[username] =bob_smith
[userpass] =psswrd
[userlevel] =user
)

)

Deleting A Row From A Database
I can't fiqure out why my delete function isn't working. I have a listing of rows in my database with an option to delete an individual row at the end: Code:

Deleting From Sql Database
I have used this script I made to delete files from a server and simultaneously remove information about the file from a database. I have uploaded the same script to a new website and it no longer works. The file does get deleted but the database line doesn't get removed. I can tell where it's going wrong by the error custom error message 'echo'ed on the page ("your file was only partially uploaded"), but I really don't know why.

PHPMyAdmin ... Deleting A Database?
I just want to delete a test database that I made, thats it. There is no upfront obvious way of doing this from my pov so thats why I'm asking.

Deleting Entries In A Database
I've got the reading and writing to a database working but want to delete entries ..... how would this be done?

Deleting Records From Database
I have another question about record deletion from
database.

For example, my database has 10 records with ids 1
through 10. If I delete id #10 then everything is good
and all the records are still 1 through 9. However, if
I delete record id #4, then in my db I would have
records 1 through 10 with id #4 missing.

Is there a command that syncs the database? How do I
go about this to keep all the ids in the right order
after the deletion? or What do I need to do to prevent
that from happenning?

Deleting Comments From Database
i have a message board that enters information to the data base fine, but where i try to create a detele for individual comments, it does not seem to work, any ideas on how to write a delete for this so that it deletes individual messages Code:

Deleting Images Associated In Database
I've got a database structure with rows containing filenames of photos on the server each with its own uploader/user and unique id number.

Can someone help me on how to delete an array of photos from the server uploaded by a specified uploader/user?

Deleting A Table From A MySQL Database
I've looked at the manual and a few other php resources, but yet I couldn't find a simple and easy way to delete a table using php. I noticed there is a destroy() function within the MySQL class, but I'm not sure how it's used.

Max Rows Cannot Add More To My Database
I need to add more rows to this table, and I cannot.....?

I'm not sure if this is a SQL problem, though when I look at the setup of the table all TYPES are set to (int)11. I'm a newby so i'm not sure if the PHP is scripted to limit database input.  I am at 2249 on my attribute rows. Code:

Assigning Rows To Unique Variables
Say theres 3 mails in the table.... named "messagetext". Now im trying to work out the best to obtain those 3 mails and put them into 3 unique variables. Which can then be echo'd... would a while loop be best and assigning them ?

Deleting Not Working - Flat File Database
I have to decrypt the $email variable in order to delete from a flat file database. I am not sure how to do this... It decrypts it and trims it to display on a select field, but I don't know how to make it delete. Code:

Deleting An Element In An Array??
Here is the problem:

I've got an array with the following elements

$array = ("ice","ice","polka","skate","polka");

thats 2 polka, 2 ice and 1 skate

Now i want someway of removing just one of the polka's from it..

so that i'd be left with:
$array = ("ice","ice","skate","polka");

what i did was a basic search with for loop and break

Code: for($x=0;$x<sizeof($array);$x++)
{
if($array[$x] == "polka")
{
echo("match ".$x);
break;
}
} alls well n good till now.. now i've got the index value(2 in this case) of the element which needs to be deleted.. but what should be done now?? is there any function which'll let me delete a particular element in an array?

Is there any other way to go around this?

Deleting An Element From An Array
I'm not being an idiot here and missing something very obvious as I seem to be prone to doing.

I have the following code:

Deleting An Array Item
I have a standard array:
$foo = array(
0 => 'abc'
1 => 'def'
2 => 'ghi');

and I have a variable, $bar, which equals 'def' ... and I want to check
my array to see if the value of $bar exists in the array, and if it
does, delete it from the array.

if (in_array($bar, $foo)) {
// what goes here???
}

I've done this before, but for the life of me, I'm drawing a blank now.
Help a bruthah out?

Deleting Array Elements
I need to delete a single element from a one dimensional array. something like.
somefunctionname $arrayname[$key]; does anyone know what somefunctionname is or how this is done?

Deleting An Element Of An Array?
How can I delete an Element of an array? Consider the following Example: PHP Code:

Deleting An Element From An Array
is there some handy and short method to delete an element from an array and than shifting the rest of elements one place ahead
e.g

array(1,2,3,4,5,6)
becomes
array(1,2,4,5,6)

Deleting Multidimensional Array
if i have a multi dimentional array, eg:

$arr[x][y] = '';

and i want to delete the enrite thing, does unset($arr); rowk, or so i have to delet the second arrays, or how do i do it???

Database Blank Rows
i made the following script and all the conditions and structure is right, i do no get errors either. but when you enter a category name andm press enter it says it added it but the database only has an extra blank row in it rather than what you entered? PHP Code:

Deleting Duplicate Entries From MySQL Database Table
The topic is related to MySQL database.

Suppose a table "address" contains the following records

-------------------------------------------------------
| name | address | phone |
-------------------------------------------------------
| mr x | 8th lane | 124364 |
| mr x | 6th lane | 435783 |
| mrs x | 6th lane | 435783 |
| mr x | 8th lane | 124364 |
-------------------------------------------------------

Quote:

Deleting Blank Entries From Array?
The resulting arrays that i get from my select statements always seem to have some blank entries, in addition to the correct ones. It is rather odd, is there any way i can scan through it and delete these blank entries? Here is the print_r of the arrays. PHP Code:

Clearing/deleting $_SESSION Array?
I have a $_SESSION array in a nested loop that I need to clear for multiple passes and cannot seem to figure out how to this. I have read the manual on unset and such but there seems to be no clear technique that I can ascertain. PHP Code:

Getting The Total Number Of Rows In SQL Database.
I know it's a bonehead question but what would a query in PHP look like that would return the total number of existing rows in a database.

Ordering Rows In A Database(output)
I am trying to do the following: My Client needs to be able to go into a certian table (we'll say table1) which has the following columns:

id - unique ID
stock_id - ID input by user when added
description - short description
ordering - what position to display

Basically this question is about the "ordering" column. The client wants to be able to select a certain row and change the ordering column to where she wants the product to be ordered. For instance:

ID| stock | description | ordering
-------------------------------------------
1 | 2222 | description | 2
2 | 3123 | description 2 | 1
3 | 2341 | description 3 | 6

So when these 3 rows are displayed through PHP the item with ID number 2 would be displayed first, then the item with ID number 1 and so on...My problem is what would be the easiest way to let her change the order of the products.

Deleting A Single Item From The Middle Of An Array?
I have an array that contain objects, I want to be able to test against the id of that object and remove it from the array. In it's simplest for I want to go from this:

$people = array('Tom', 'Dick', 'Harriet', 'Brenda', 'Jo');

...to this...

$people = array('Tom', 'Dick', 'Brenda', 'Jo');

The fact that the items in the array are objects should not matter right? Plus I've already written my loops and conditionals to check which item i need to remove.

function removeItem ( $item ) {
   $len = count ( $_SESSION['basket_arr'] ) ;
   if ( $len == 1 ) {
      emptyBasket ( ) ;
   } else {
      for ( $i = 0 ; $i < $len ; $i++ ) {
         if ( $item->id == $_SESSION['basket_arr'][$i]->id ) {
            //$_SESSION['basket_arr'][$i] must go
         } } }}


Updating Multiple Rows In Database On The Same Form.
Im writting a content management system that generates menu's / pages etc. A feature i want is for people to be able to order the menus themselves.. ive created a page.. that looks thru all the records in the mysql database and lists them and also displays a text field called "ORDER" ie.

Menu Header 1 [ 1 ]
Menu Header 2 [ 2 ]
Menu Header 3 [ 3 ]

.... and so on.. ([ ]represents a text field...) what i want to do now.. is be able to press submit and all the rows in the same table update. PHP Code:

Updating Multiple Database Rows Simultaneously
I'm having some trouble with something that should be relatively easy. I
want to update multiple rows in one of my database tables simultaneously.
In my table I have these values:

imageID
image_order

I want to be able to modify the image_order column where imageID = imageID.

imageID | image_order
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5

I want to be able to pull these values into a form and allow the user to
edit the image_order value. So my updated table might look something like
this:

imageID | image_order
1 | 2
2 | 5
3 | 1
4 | 3
5 | 4

The problem lies in the form handling script. How can I pass multiple sets
of imageID / image_order values to an sql update query?

I can pass one set without problem. But I want the user to be able to edit
all of the image_order values from one page.

I've tried passing multiple image_order values by initialising an array and
using a foreach() loop to extract the values but I can't think of a way to
pass the corresponding imageID value. I can grab all the imageID values
again in my form handler script using an ORDER clause to ensure they are
pulled in the same order as the form script but again, I can think of no way
to combine this with the img_order array sent from my form.

Displaying An Array From Rows Retrieved From Mysql
I have a web site where users can add pages to it. When they make a new web page the url of the page and username of the user who created it is stored in Mysql. When the user logs back in the users previously made pages are displayed as links or atleast should be. Below is the code that I am using. PHP Code:

Parse HTML Table Rows Into Array
I have a script that extracts an HTML table from a page into a text string. I would like to parse each row of the table into an array named "$rows". I would like to keep the html intact so that I could re-create the same table like: Code:

Insert Data From Mysql Rows Into An Array
I am working on a project where I need to select rows from a table called 'hub' and take the rows where 'to_id' = '$to_id' and put them into an array. How can I get MySql info into an array?

I Have A Weird Database Problem: It Is Returning Spurious Rows Withall The Fields Concatenated Into One
I have a PHP program that almost works. I'm running it from the command
line and simulating a form using a GET method. That part is working,
but I get spurious records with all of the fields concatenated into a
single field.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="content-type">
<title>eqdb_read.php - Read the Equipment Database</title>
</head>
<body>
<small>This document last modified
<script>document.writeln(document.lastModified)</script>.</small>

<?php
$_GET['hostname'] = $argv[1]; // grab [1] because [0] holds the script
name FOR DEVELOPMENT ON THE COMMAND LINE ONLY

$hostname = $_GET['hostname'];
if ( is_null($hostname) ) {
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
Host Name:
<input type="text" name="hostname" /> <br />
<input type="submit" name="Lookup by hostname" />
</form>

Batch File Deleting And Folder Deleting
I have a folder in my web site where I used php to create and copy in files. but now I can't delete them easily. The only way I know how that is possible is through php. I get an error the following ftp error:

550 th: Permission denied
I had the chmod() set to 0777 on every file and folder. But I still seem to loss control over the files when I try and do things with them through other means.

I think it is because the user I use to access the files via ftp a diffrent user. So I tryed to add a function with chown() for the new files I was posting and uploading. It didn't work on those new files. so it looks like the only thing I can do is use the unlink() function which deletes the files fine.

The only problem is now I have something like 100 sub directories all with files in them. I need to figure out a way to batch delete them. I can't find a script that goes through and finds all file contents including all sub directories and unlink those things.

I found some that will use a for loop to list out the contents of a folder but it is just files. No sub directories. Any body got any ideas on which functions I should use or know where a script is that I can base mine off of.

I am not sure how to approach this since what I tryed with chown and chmod has failed thus far. I currently have no code and am starting from scratch on this batch flushing of my directory.

Deleting From Database, "SQL Sytax Error"
I searched the forums and I couldn't come up with anything, so I'm sorry if this has been solved before. But my problem is that when I want to delete a comment from the database, it just says, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1". At line one I have a Session_start...and I doubt that would interfere with deleting.

Here's my query:
$com = $_GET['del'];
if ($com != NULL && is_numeric($com)) {
  if ($ip == $okip) {
mysql_query("DELETE FROM `comments` WHERE `id` = '".$com."' LIMIT 1 ");
echo "Comment has been deleted.<META HTTP-EQUIV="REFRESH" CONTENT="2; URL=show.php"> ";
}
else {
echo "You do not have permission to delete comments."; }
}

Count Amount Of Rows In Same Query Of Selecting Rows
I am selecting some rows from a table and i wonder if i can count
the amount of rows in that same table in the same query? I tried something like: PHP Code:

Cookies From Database Variables
I'm setting cookies on my machine and I know they are functioning properly if I set a specific value to them (such as "1") but if I try to select something from the database and then put THAT into the cookie -- it won't work. Is there anything wrong with the below code? PHP Code:

Sorting Variables From Database
I have a function listed below, right now it sorts by $member_id I believe. I desire the same output ie.. member names, but I would like to sort it alphabetically by name. Is that possible? PHP Code:

Selecting Variables From Database
I can select the tables, I can pull out the information, what it's not doing is grabbing and showing my id as well as the others that are approved on my list.

My driverID is 5, on my list is driverID 6, when I query the bulletins database, it should pull everything from driverID 5 and driverID 6, but it's only showing driverID 6. How do I get it to show my driverID as well? Code:

Inserting Data Into Database With Use Of Variables
this code insters data correctly into the 1st table but not the second. I bet a simple modification is required but i cant figure it out - ive tried many things: Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved