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




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:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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.

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?

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 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?

Multiple Items In Foreach()
Can someone tell me what im doing wrong with the code bellow please? I get print_ticket called lots of times, with 1 as the hash,name,ticket_no responce.

(i have chequed that the query is returning the right results).

$return = pg_query($pg_connection, $query);
        $data   = pg_fetch_array($return);                   

foreach ( $data as $temp ) {
   
echo print_ticket ($temp['hash'],$temp['name'],$temp['ticket_no']);   
}

Multiple Arrays And Foreach To Put Into A Mysql Db?
I created 3 arrays with data and i want to insert them i a mysql db. PHP Code:

Accessing Multiple Arrays Using Foreach
I have been searching all afternoon for an answer to this and haven´t found a solution so my last resort is asking here I am collecting links from a few documents on our site using this:

<?php 
  $data = file_get_contents('http://www.example.com/');
  
   preg_match_all("/out.php?url=(.+?)" target/",$data,$match);
   preg_match_all("/class="id" title="(.+?)"/",$data,$desc);
   
  foreach($match[1] as $url ) && foreach($desc[1] as $fulldesc){
     
         echo urldecode($url);
         echo "| $fulldesc<br>";
        
          }?>

Basically , I want to output all the links and their respective descriptions separated by a pipe character.

But reading from the two arrays is giving me a bit of a hard time.I now know I cannot use the && operator, I just left it in so you guys could see what I´m trying to do. How can I do this?

I´m not much of a programmer but from what I have read the other option I have is using multi-dimensional arrays? I might be extracting the URL, the description and then some more data later on so this might be a better approach.

Inserting Multiple Rows Via The Web
I would like to have a form that can have multiple rows inserted on the same page and then submitted to the database in one click. How would I go about doing this with, say, three text fields that are named "name", "email", and "URL"?

Updating Multiple Rows
I am trying to create a form to update multiple entries in a mysql databse. This code below is rough, but it is working to the point wher it pulls the data, displays it in the text areas (but it does not go past the first white space in displaying, that needs to be fixed), and then I can alter the text fields, check a box, and hit submit, and it will update the fields, but the new value is size=20. I also can't update more than one record at a time, which defeats the purpose. Any ideas?

Updating Multiple Rows
I have a databse with a list of employees, I also have in that database a field that shows their status 1- Out, 0 - In. What I would like to do is make a page that will list all of the employees with their current status in radio buttons that I could then make changes and submit that will then update the database with the changes for all of the employees. Here is the code I have for the first page: PHP Code:

Insert Multiple Rows At Once
i have a strange problem. I can't get php to insert multiple rows at once in
a MySQL database. I use the
$sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',
'$e')";

I want to insert 5 rows at a time in the database, but it only inserts every
5th record. For example:
1. AA
2. AB
3. AC
4. AD
5. AE

I only find 5. AE back in the mysql with id 1.

How can I insert multiple rows at once ?

Inserting Multiple Rows Into Db At Once
i have a text file with a BUNCH of different words, each on its own line, curious if there is a way for me to import them into a simple table (with an id column and name column) along with an id based on time().

im not very good with loops, but im assuming this is the best way to do it. For instance, have it loop thru each word and give each word a unique id based on time(). any simple methods out there?

Selecting From Multiple Rows
I am trying to achive the following but cant work out the correct format: PHP Code:

Any Example For Updating Multiple Rows ?
I need to update multiple rows with php, any example for this technique ?

Updating Multiple Rows At Once
A client of mine would like to be able to turn on and off zip codes for certain states. So on the admin side of things I have two radio buttons on and off one has a value of 1 on the other has a value of off. I want them to be able to set all the zip codes to on and off at one time with one submit.

I have everything working except for multiple zip code changes it will only update the first one. Code:

DELETE MULTIPLE ROWS
with the code below i delete 1 row even if several rows are selected, what should i do to be able to delete as much rows as much i select at once. Code:

Echo Results Into Multiple Rows?
Ok so i got a client who wants something which i know will fall into noob territory for most of you young padawans however.

All i need to do is bring up results from a mysql database and then list the results into a table using a while loop, thats the easy bit and ive done that loads a times before, however this time rather than making a while loop that draws a table fills it then for the next database entry draws another table below it and echos the second entry into it, im buggering it up cos i need the second entry to fill the second column rather than draw a new table,
i need rows of 3 or 4 results then go to the next row

ID 1,2,3 got into column 1,2,3 then ID 4,5,6 go into the second row columns 1,2,3.

Feel like ive been noobed :D

Do i need an IF clause somewhere in the while or an extra variable for the counter or what? Doh!

This is what happens when your self taught and learn it one way always do it that way then get bedazzled by summat that should be so simple,

ideas would be appreciated :D

diegomh7 aka dildego

p.s thx to all for the dynamic page generation post :D

Heres how i need it to look more or less anyway, the next 3 entries from the database need to appear on a row below and so on...

Multiple Rows And Alternate Color
Below I found a code to make multiple colums from the output of a DB, how
can I incorporate alternat colors to the multiple row snippet?

<?php
//set the number of columns
$columns = 2;
mysql_connect('localhost','','');
mysql_select_db('test');
$query = "SELECT stuff FROM mystuff ORDER BY stuff";
$result = mysql_query($query);
//we add this line because we need to know the number of rows
$num_rows = mysql_num_rows($result);
echo "<TABLE BORDER="0">";
//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
$row = mysql_fetch_array($result);
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<TR>";
}
echo "<TD>" . $row['stuff'] . "</TD>";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
echo "</TR>";
}
}
echo "</TABLE>";
?>

Updating Multiple Rows (MySQL)
I have a piece of code which works perfectly when I want to insert multiple rows in a MySQL table. I am storing links in one table, categories for these links in another table and a link_category table (Id, LinkId, CategoryId) to attach one or more categories to the links.

The $AddCatId (array) comes from a form where the user can select one or more categories for a link. PHP Code:

Submitting Multiple Rows With One Form.
I am trying to create a form for my users to submit multiple rows to a databse, I have a few questions.

1. I would like the form to have an option before they start filling out the form, the option should be how many kinds of pop they would like to submit with options 1-5.

2. I would like the information that they submit to be submitted to the database but, I would like it to be in different rows. eg 5 kinds of pop 5 rows.

Return Multiple Rows From Sql Statement
i would like to filter out a bunch rows from a table of sql row
results.
i have a checkbox on each row named checkbox[x]
(x = the current row id)
i will submit the form and take all the rows that are checked and
filter out the ones that are not checked.

so if i had 10 rows and i checked 3 of them then when i submit the
form only those 3 rows will show up.

I was wondering what was the best way to call those rows in the sql
statement.

Would i just loop through the rows that were checked and add them to
the WHERE STATEMENT using the OR condition?

select * from rows where id = 3 or id = 2 or id = 6 or id = 10

so basically i would do something like this with the php code.
$sql = "select * from rows WHERE 1 ";
foreach ($_POST[checkbox] as $check){
$sql .= " OR id = $check";
}

I just think its slow to use so many OR conditions in one sql
statement, but i cant think of anyway else to do this.
Is the way i want to do this a good way?

Update Multiple Fields And Rows
I am trying to create a form that can update mutiple fields in a mysql database. I need it to be able to also update mutiple rows of the same field. The code below doesn't update, it actaually delets all data from the 4 rows. PHP Code:

Retrieving Multiple Rows Advice
let's say I've an array of articles's id

$arr_art_id=(1, 551, 2015, 6 .......n )

what option is better (1 or 2), in order to achieve better performance?

(pseudo code)
1)
for i=0 to array count{
select * from articles where articles.id=$arr_art_id[i]
mysqlquery($sql)
//do whatever i have to do
}

2)

$or =''
for i=0 to array count{
$sql.= $or . 'articles.id='. $arr_art_id[i];
$or ='or'
}

$sql = 'select * from articles where' .$sql

mysqlquery($sql)
//do whatever i have to do

Updating Multiple Rows Is Not Working!
Everytime I try to update 'picorder' in the 'propertiesimages' table, picorder gets converted to 1. I'm using PHP 5.2.4, MySQL 5.0.45, and the table is InnoDB. 'propertyid' in table 'propertiesimages' is a foreign key to 'propertyid' in 'properties' Code:

Update Multiple Rows With Variable IDs
I'm trying to update multiple rows on my database using one form. The problem is that the number of rows on the form is variable, and the ID for each row is also variable...

   $Team = $_GET['Team'];
   $Game = $_GET['Game'];
   $result = mysql_query("SELECT * FROM data WHERE Team='$Team'",$db);
   while($myrow = mysql_fetch_array($result)) {

echo '<input type="hidden" name="PlayerID" Value="', $myrow["PlayerID"], '">', '<input type="hidden" name="Game" Value="', $Game, '">', $myrow["Team"], ' - ', $myrow["PlayerName"], ' - ', $myrow["Owner"], ' - Points:<input type="Text" size="5" name="Points" value="', $myrow["$Game"], '"><br>';
}
?>

That is my form. When I POST the data I only get the data from the last row that is echoed. I assume that the problem is that the names of my inputs are static and will be overwritten each line, but if I change them to a variable, how can I tell my form to know what they are on the other side? From my limited knowledge it looks like I want to pass an array through POST, just don't know how to do that!

Insert Multiple Rows From One Form
I have one form submitting a dynamic amount of identical entries depending on how many are generated from the query for the specific date. Each form "set" consists of four values, qid#, a#, a#, a#. So for example, three sets of these equal forms will create the following values:

qid1, a1, a2, a3
qid2, a4, a5, a6
qid3, a7, a8, a9
....
etc

I would like to insert each of these "sets" of values as a new row in my table. Right now I'm using the following code and I'm having problems: Code:

Update Multiple Rows And Fields. Simple?
Hi. Im trying to create a form which will enable the user to update mutiple rows and fields, using checboxes to select and a submit button. The code below updates the field, but it always inserts the last row in the db. It inserts it in the selected row number (catalog), but it inserts the same data over an over (the last row in the db). Also, if more than one checkbox is selected, I get error Error in Query: >>>UPDATE catalog SET Name='Fred' , StreetAddress=ûû yadda, City='somewhere' , Country='USA' WHERE catalog=(8,30)<<<. Error: You have an error in your SQL syntax near &#3930;)' at line 1
(8,30) are the numbers/checkboxes I selected and the data (fred, etc.) is from the last row, and is not what I type in the text fields. Ideas? Thanks.

Counting The Contents Of Multiple MySQL Rows
Ok, I'm working on a poll for my site, which uses a mysql db.. I need my script to count the number of votes total, so I can take a percentage out of the total number of votes..

The table has the following rows.
vote_id | vote_option_id | vote_option_text | vote_result


I need to add up all the numbers under the "vote_result" columns.. but I hardely even know where to begin.

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 Rows With One .html Page
I am trying to create a form to update multiple entries in a mysql databse. This code below is rough, but it is working to the point wher it pulls the data, displays it in the text areas (but it does not go past the first white space in displaying, that needs to be fixed), and then I can alter the text fields, check a box, and hit submit, and it will update the fields, but the new value is size=20. I also can't update more than one record at a time, which defeats the purpose. 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.

Option Selected Multiple Rows Logic
I am having problem getting the logic to work to get a multiple option box to get populated from the database and select the ones which are already in the database. Here is my code: PHP Code:

Adding Multiple Rows To Table Using Checkboxes
I'm looking to select using checkboxes certain rows from the results of 'table a' and add the selected rows to another table using checkboxes. I Have had limited success adapting some code for deleting multiple records using checkboxes. Code:

Updating Multiple Rows In A Table In Mysql
ok so im making this form that updates multiple rows in the mysql database but the thing is that the number of rows is a variable so once it may be one row once it may be 31 rows. is there anyway i can do this using a while loop? or even is there a way to do this period?

Displaying Multiple Queries To Same Table Excluding Different Rows!
i've got a table with 224 town listings and their ID's in it from 6 counties, and I want it to displayin a 6 columned table, each county getting their own column. Anyway, here's what I've got and what's happening: PHP Code:

Ordering & Limiting Multiple Table Rows By Date
My goal is to select rows from two tables 'shoot' & 'video' and have mysql order those tables by date and limit the number of rows returned. I want to list the latest 10 rows but am uncertain how many rows from each table will be the latest. I may have more recent shoots than videos or the opposite. How can I use a single ORDER BY and LIMIT statement for both selections? Code:

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.

Multiple Table Rows In "While" Loop
I have the code below with two table rows, but the second row won't display any data. How can I make both table rows work? Code:

Checkbox Is Checked
how do u say that if the checkbox is checked, than do something.

For Each None Checked Checkbox
I need help with foreach none checked checkbox as value, can you even do that. I tryed the !isset(); function but i'm not sure it would work because the none checked box would not of run with the $_POST ( i think ) this is an example table of what i'm looking for help with:

({num}) = the value
[] = the checkbox.

(1)(2)(3)(4)
 [] []  [] []

the person checks the one(s) they wish to keep and the none checked ones get swaped for diffrant values. I'm not quite sure if it is possible, but i will ask anyway to see if anyone as a solution.

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:

Unlink Files That Are Checked
Has anyone written a script where you can view files in a directory and then delete them? Next to each file name is a check box. If you check the check box and click a delete button, the file will be deleted from the directory it resides in.

This script allows me to upload files to the upload folder on my webserver. I can also view all files in the upload folder. The only thing I can't do is put a check next to the file I want to delete and click the delete button to delete the file from the upload directory. Any ideas????

Thanks,

Jamie


<html>
<head>
<title>File Management</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<?
//check for file upload
if(isset($uploadedfile))
{
$directory = "upload";
$path1= dirname($PATH_TRANSLATED)."/$directory/";
// assign our path in a form PHP for Windows understands
$dest = $path1.$uploadedfile_name;

set_time_limit(120);

// Free the memory allocated
Copy("$uploadedfile",$dest) ;

// Destroy the file now we've copied it

unlink($uploadedfile);
}
?>

<p><b><font size="6" color="#400080">Georgia Power - Plant Bowen File Upload and
Download</font></b></p>
<p>Click on the file you would like to download:</p>


<?
// Here I print out the list of files from the upload directory, with a check box next to
// each file. I put a check in the checkbox if I want to delete a file.

$file_array = array();

$dir = "upload";
$sPath= dirname($PATH_TRANSLATED)."/$dir/";

function GetDirArray($sPath)
{
global $file_array;

$handle=opendir($sPath);

while (false!==($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
print $file_array[]= $file;
print "<INPUT TYPE=checkbox NAME="checkbox".$i."" value=checked>";
print "<br>";
}
}

closedir($handle);
sort($file_array);
}

// This code is supposed to be deleting files that are checked........
if(isset($checkbox))
{

unlink($file);
}

GetDirArray($sPath);
?>

//This is the button and browse button to upload files to the upload folder.
<p>&nbsp;</p>
<FORM ENCTYPE="multipart/form-data" ACTION="<? $PHP_SELF ?>" METHOD="POST">
<p>
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000">
Upload This File:
<INPUT NAME="uploadedfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Upload">
</p>
</FORM>

//Here is the delete button to delete files who's checkbox is checked.
<FORM ENCTYPE="multipart/form-data" ACTION="<? $PHP_SELF ?>" METHOD="POST">
<input type="submit" name="delete" value="delete">
</FORM>
</body>
</html>

Only Allow X Number Of Items To Be Checked
I have a function that renders out tag categories, and then all the tags within said category. Each tag has a checbox beside it, i am wondering if it's possible to only allow a user to check 4 tags. Here is the function: Code:

Database Remembers If A Box Was Checked Or Not
if the input is a check box, how would i set it up with the database so that it remembers if a box was checked or not.


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