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




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.




View Complete Forum Thread with Replies

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

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?

Generating Multiple Alternating Columns And/or Tables Within Tables
I am having a little bit of trouble generating the code for a table with 2 columns. The columns contain tables within themselves. Not sure why as that part was an existing design. Here is the output so far and it is correct but not how i want it to be (i'll explain) Code:

PHP / MySQL -- Moving Rows Between Tables And Dealing With The Primary Key
Let me start by saying that I'm still very new at PHP/MySql and will
take any advice. :-)

The issues is that every once in a while users get an error when they
use this code. I believe the issue is that I'm copying the primary
key as well as the other data in the row. So, my thoughts on fixing
this are to just select everything but the 'pkey' column, but I'm not
sure what would result from that. Would MySql use the next auto
incremented primary key for the 'pkey' column when the data is moved
into the table, or would it just leave it blank?

Also, is their a better strategy for moving data from one table to
another than the one I have taken?

///////////////my variables//////////////
$newtablename == name of the target table
$tablename == name of the current table
$pkey == the table's primary key (big int, auto
incrementing)

//////////////The Code////////////////////
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());

/////////////My move Queries//////////////
$sql1 = "insert into $newtablename select * from $tablename where
pkey = $pkey";
$sql2 = "DELETE FROM $tablename WHERE pkey = $pkey";
$result1 = mysql_query($sql1) or die(mysql_error());
$result2 = mysql_query($sql2) or die(mysql_error());

Selecting Multiple Values From Multiple Tables Using Checkboxes
I've been struggling with this for a bit but cannot seem to find a simpler, cleaner way of doing this.

a. I have a Table A - Customers , Table B - Contacts .
b. I have a form where a user types the first few alphabets of a customer name and then gets a list of contacts, cities.
c. The user is supposed to select multiple options from this list and then send that data to another form for processing.

I'm able to only pass data from Table A, not from B . Could someone please have a look at the 2 snippets of code and advise? And is there a way both these php scripts could be combined in a single one ? Code:

Grabbing Data From Multiple Tables For Multiple Requests
Here's what I'm trying to get at.

A table that displays all the Process Server's name, the number of summons's he has out within 7 days, 7-14 days and 15+ days...pretty simple, it's just a report so management can stay on top of how many papers are out.

I've got the server_information table with the server name and ID. and a case_information table with the serverID.

I've got a while loop that displays all the server's name, the problem is when I try to get the # of cases....here's what i've got so far. Code:

Multiple Users, Multiple Tables, One Form
I have a small group of users that will submit their 'goals' via one form (placed in a postnuke block). I have created one table (mysql) for each user to collect collect their goals. I need some direction in writing the php that will submit the form data to the correct table based upon the users Postnuke login.

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?

AVG() Through Multiple Tables?
I'm trying to get the average of several columns [all with the name of SIR] in several different tables, and display the result. My code is giving me a "please check the manual depending on your MySQL version.." error. Here's my code:

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:

Search Multiple Tables
I have a search form in PHP for MySQL.

Is it possible to search multiple tables with one select statement?

Inserting Into Multiple Tables?
I need to increment the value of 'id' in 5 tables whenever it is incremented in another table.... Is there any way to do this? How?

Multiple Tables Query
I have a roster script that handles multiple tables ($orderof) and within those tables multiple divisions ($sword). The only problem is that, nothing is getting displayed -- though there are no errors (systematic [to my knowledge] or parse). PHP Code:

Getting Data From Multiple Tables
I was wondering if anyone can tell me how to get data from several tables and save them in variables for further processing?

One Form, Multiple Tables
I have a form which is used insert data into multiple tables. Each table relies on the data inserted from the previous table. The problem I think I am having is that the data is not avialable by the time the next query is run. code:


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