Code Loop Through The Array And Delete Everything From Each Of The Tables
Will this code loop through the array and delete everything from each of the tables for a particular user. PHP Code:
$tables = array (
"user",
"user_info",
"foo",
"bar"
);
foreach ($tables as $value) {
DELETE * FROM $value WHERE user=$username
echo 'user deleted from '.$value;
}
Also is there a better way to delete all user info across multiple tables? This seems as if it could be quite inefficient.
View Complete Forum Thread with Replies
Related Forum Messages:
MySQL - Delete Across Two Tables. OT
i cant find the MySQL newsgroup, however i am hoping to pick up on some expert advice from php/mysql gurus here. I'm having some trouble performing a delete across two tables. The tables i have are: questionnaires (id, name); questionnaire_questions (questionnaires_id, id, name, qf_type) The questionnaire_questions table contains a list of questions for a specific questionnaire (indicated by the questonnaires_id). I would like to remove a questionnaire, and when doing so all corresponding questionnaire_questions who have matching id's (questionnaires.id = questionnaire_questions.questionnaires_id). I have this statement, however it only works if a questionnaire has questions... however i would like it to delete even if no questions exist for that specific questionnaire. The SQL i am using is: delete questionnaires, questionnaire_questions FROM questionnaires, questionnaire_questions WHERE questionnaires.id = questionnaire_questions.questionnaires_id AND questionnaires.id = THE_QUESTIONAIRE_TO_DELETE_ID
View Replies !
Want To DELETE Row FROM Multiple Tables
I'm looking to delete a single row from multiple tables where they all share a common column name, primaryKey, and a common value - $POST_[primaryKey]. Here is the code: $query="DELETE FROM assetinfo, emplhistory, income, newuser, preliminfo, primarydata, reoinfo, residencehistory WHERE primaryKey='$_POST[primaryKey]'"; $result=mysqli_query($connection, $query) or die (mysqli_error($connection). " <br> Could't run DB Query to Delete Borrower"); And here is the error msg I'm getting: 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 'WHERE primaryKey='jarreola2'' at line 1 Could't run DB Query to Delete Borrower Is my query valid? Any other ideas on how to delete a row from multiple tables?
View Replies !
Delete From 2 Tables (join)
How are we all doing this fine day small problem "man do i hate joins" I have two tables "categories" and "links" Links carry the cid field from categories. PHP Code:
View Replies !
While Loop Two Tables
I am just getting started with some PHP/MySQL work and have come to a roadblock. I am going to be working on sites for bands and I want them to be able to update their site with their all their album information… I set up two tables in my database one for the albums and one for the tracks Code:
View Replies !
Loop With Html Tables
I currently have it to where the user can input data and it is stored in a mysql db.. I am having problems with the output portion and it being formatted the way I would like it. I want for it to print the all the data results inside of html tables... 5 across (columns) and 2 down (rows) so a total of ten records are printed out. After 10 I want it to generate a second page with the next 10 records.. these records will all be sorted by date.. Code:
View Replies !
Nested Loop, 2 MySQL Tables
I have a set of nested links, and at one time each category one had all the same subcategories. Now that has changed - each category has different subcategories. I have a tree menu, but now it just shows all subs under each category, of course. I have 2 tables - one for categories, one for subcategories - they are related by the categoryID. I think I have the SQL fine (have tried several different versions - see most recent/uncluttered below), but how do I get it to work correctly in the tree loop? SELECT DISTINCT cat.catName, cat.catDesc, subcat.subcatName FROM cat, subcat WHERE cat.catID = subcat.catID; Tree example: cat.catName(1) subcat.subcatName(1) subcat.subcatName(2) cat.catName(2) subcat.subcatName(3) subcat.subcatName(4)
View Replies !
Creating A Loop For Html Tables
Nesting loops to create html tables with (incremented) variable names is a task I am weak at. What I have is a quiz that lists each person in a row then shows the next name in the next row. I could not figure out how to loop thru this, so I did it all by hand (I know, php would be more efficient, but I could not get it to work). Code:
View Replies !
Loop Problem When Trying To Query Multiple MySQL Tables
I will try and explain this as best I can. I have a database with tables separated by year (exp. 1994data, 1995data, 1996data, etc.). I am trying to perform a search that will allow the user to enter a value, iterate through the tables and echo the result. Here is the code I am using: Code:
View Replies !
Code To Delete
Table name: Subjects subject_id student_id (foreign key) subject_name i want to delete all subjects by the student where the student_id is x wht would be the code to delete in tables having relationship
View Replies !
Delete Code Error
i'm trying to delete old entries in the database but i'm getting a "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result " when the code is ran. Code:
View Replies !
How To Code Add,find,delete Buttons
Hello, I am new to PHP and Postgres. I am creating a page that displays a form to allow entry of details about a piece of equipment. The form is intially blank. I want to have 3 buttons: Add, Find, Delete. It shows only one piece of eqipment at a time. The user can fill the form out, press Add and it will insert into the database. Or they can enter the equipment ID, click Find and then modify or delete (by pressing the Delete button) the returned record. I am able to create the form and the SQL but I am not sure how to have the buttons fire to execute the PHP code for each functionality (Insert, Find, Delete, Update). Can someone point me to a resource that shows how to do this?
View Replies !
Dreamweaver Generated Code To Delete Record
I use the dreamweaver generated code to delete a record, how would i add some code to it to delete the files (images) stored in my../images folder, that are linked to the record being deleted, there field names are photo1, photo2, ect..... and there image names are stored in the database Code:
View Replies !
PHP Code To Move Between Tables
I am trying to write my very first PHP code and it is not going well at all!! I am trying to code a way for someone to click a link to move an item (and all of its variables) from one table in the SQL database to another. I thought I had it working but it didn't copy over everything so I editted it and now I get an error: "Column count doesn't match value count at row 1" Also, I don't know what code I need to include to remove the info from the first table. Right now it is just copying it. Here is how the database tables are layed out.One is called "pets" and the other is called "pound_pets" Code:
View Replies !
Run Code Every 3 Times In A While Loop
I need a certain block of code to run inside a while loop every 3 times its run but I cant figure out how to write it. I came up with a sort of static fix but I need it to be more expandable. Here is what I've got inside the loop so far. if ($num == 3 || $num == 6 || $num == 9 || $num == 12 || $num == 15 || $num == 18 || $num == 21 || $num == 24 ect...) { echo('</tr><tr>');} The loop output 3 profiles with images and names on each line and then goes to a new line for the next 3 using tables. Is there a way to write this so it runs every 3 on to infinity and not have to input the numbers manualy?
View Replies !
Altering Tables In Database Through Php Code
i am writing code for a software for manging staff of a clinic.. and i want that as soon as i insert a new staff a new field to be created in one of the database table. One, more thing i want to know is that, that in my software i even want to add data to the fields code will be creating...so how should i write the code for creating fields by altering table and how to use these fields in database.
View Replies !
Code Wont Continue After While Loop
Im using the following code to describe a database table. It works perfectly fine when echo() is used to display field titles, but no code after the loop is running: $result = mysql_query ( "DESCRIBE `test`" ); while ( $r = mysql_fetch_array ( $result ) ) { extract ( $r ); echo "$Field<br>";} echo "bla bla"; <---- this code doesn't run! Ideas?
View Replies !
Inserting Code Between Items In A Loop
I need to show an evil advertisement after every two loops in order to get rich. I have my "while" loop, simplified for illustration. How to I put a javascript call after each 2 rows? while($result = mysql_fetch_array( $data )) { echo "a bunch of HTML"; echo "<div class="descr">Posted on " . date('D j M Y',$result['posted']); echo CutText(strip_tags($result['descr'], '<example>'),100); }
View Replies !
Delete From Array
let's say I have an array $letters(a,b,c,d,e,f) is there a function that will remove 'd' from the middle. I'm looking for something like array_delete($letters,'d');
View Replies !
Delete From An Array
If I have an array like: $myArray = array('Firstly' => Ƈ', 'Secondly' => ƈ.0', 'Thirdly' => 'three'); How do I delete a specific key and it's corresponding value? I know you can array_shift and array_pop ... but I want to be able to say. Array_Remove($myArray, 'Secondly'); ... or something like that how do I do it?
View Replies !
Delete/drop Value From An Array
Hi, I have an array of values that I am matching against a string and I want to drop the value from the array if it is in the string. My array looks like: 0=>val1, 1=>val2, etc I understand how to check to see if the value is in the array, but not how do get rid of it if it is.
View Replies !
Delete Array Element
How can i delete an element from one array. Let us suppose that i've an array of 10 elements $a[0], $a[1], $a[2]...etc And when i delete $a[2] i wanna the elements to be re-ordered like this $a[0] will be the same $a[0] $a[1] will be the same $a[1] but $a[2] will be the $a[3] element i had before deleting $a[2] It would be called in Delphi, HOW TO DELETE AN ELEMENT FROM A COLLECTION? Is this possible? Have i to use another type of data? Hope you've understood the idea.
View Replies !
How To Clear/delete An Array?
I am using an array in a loop, and every time I loop I need to have the array be empty. I cannot find an array function to empty the array, or clear it. Have I missed something somewhere ( I suspect I have) ?
View Replies !
How Do I Delete Items From Array?
I can add several items to the basket, but how do I delete one from the basket? I want to delete any of the added items. Here is my code for creating the array and adding items to it. // creating the array $item = array(); $item['id'] = "1"; $item['price'] = "100"; $item['quantity'] = "1"; // add item $_SESSION['basket'][] = $item;
View Replies !
Simple Delete From Array?
Any way to do a simple delete from array? In other words, what would be the *easiest* (and fastest php runtime) way to delete "banana" from the following array: $my_array = array( "apple", "banana", "grape", "lime" ); .....so that $my_array will now be: $my_array = array( "apple", "grape", "lime" );
View Replies !
Delete Element Of Array
I am trying to check if any of the elements in a certain array (which is to be inserted into a mysql table) are already listed in the table. For example I have an array containing multiple URL's, and I want to check whether any of these urls is already in my table. If it is i need to remove that particular element of the array. Can anyone point me in the right direction, i am currently trying array_search and in_array.
View Replies !
Array Problem - Array In The Loop
I've been staring at this for ages and I cant see the problem: It should output 1,2,3,4 but I get 1,2 I'm losing the 3,4 somewhere but I cant see how as it is added to the array in the loop. PHP Code:
View Replies !
Delete File (array Setup)
I have this code that i use in a different site that deletes one file(photo). how can i build an array to delete three files photo1, photo2, photo3,. <?php $myFile = "../images/news/". $_POST['photo']; if (!empty($_POST['photo']))      { unlink($myFile); } else      {        echo  "";      } ?>
View Replies !
Completely Delete A Specific Array Index
I was wondering if anyone could tell me if there is a way to completely delete a specific array index once it has been set. For instance, I have an array with 50 indexes (0 - 49) sizeof = 50. Now, I want to eliminate 10 indexes, making my array sizeof 40 and having array indexes 0-39.
View Replies !
Safe To Delete Elements Of Array In Foreach
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to a temp array and delete afterwards if necessary but since I'm actually working in a nested situation this could get a little messy. I guess I could set there values to
View Replies !
While Loop From Array
I have an array, let's call it $namesarray which is full of names. How do I create a loop such as a while loop to repeat for every value (name) in the array?
View Replies !
Array And Loop
I am making progress but still not coming up with the right solution. I have a horizontal nav bar that has drop down navigation - the drop down navigation is populated from my database based on the user the list will be different. Meaning I have 1 table that stores the navigation links (called sanavbars) and another that stores the users (called sauser) and then a 3rd table that stores which links from sanavbars each user has access to. Now I want to change the class of the horizontal nav bar which contains the current page (e.g. basename($_SERVER['SCRIPT_NAME'])) in one of its sub navigation links.
View Replies !
Loop With Array
I have this array: array('a'=>array('a1','a2'), 'a1'=>array('a1.1','a1.2','a1.3'), 'a1.2'=>array('a1.2.1')); and I wish to do a replacement of values so it becomes this: array('a'=>array(array('a1.1',array('a1.2.1'),'a1.3'),'a2')); Have been trying and trying but I still can't figure out.
View Replies !
Array Loop
So I have the following code: function check_blank() { $options = array($order_number); for($i = 0; $i < count($options); $i++) { if(strlen($options[$i]) == 0) { $options[$i] = $na; } } } The loop only has one element right now, but usualy has over 20. It's simply suppose to go though each array element(which are form fields), and check if they're empty or not. If they're empty, I assign $na ("N/A") to the value. It's not it's not blank, leave the variable as is. I've been at this for a while, trying a lot of different things.
View Replies !
Array + Loop
How to use loop in array? For example, if I want array that contain 100 years, but I don't want to write $year =array ("1900","1901","1902",...); Can I use loop in running these numbers in a very simple way?
View Replies !
Loop Through Array Twice
I'm grabbing data from a SQL query and using while ($a_row = mysql_fetch_array($result))to loop through the results (which is working on the first loop). The problem is that the 1st set of results I want belong in 1 DIV on the page. Then I need to loop through the same array again, grabbing different data and placing it in another DIV on the page. Here's what I have: $i = 0; while ($a_row = mysql_fetch_array($result)) { $i++; //in the first DIV print "First set of DATA"; } while ($a_row = mysql_fetch_array($result)) { //in the second DIV print "Second set of DATA"; } What am I doing wrong?
View Replies !
Loop Array
In my database I have 44,55,66,1,365. I want to explode this and show each one on it's own row. How can I do this with this code? PHP Code: echo '<div align="center"> <table border="0" width="95%" cellspacing="1">' $user = $HTTP_COOKIE_VARS['RLNZ']; $result = mysql_query ("SELECT * From members where user = $username"); $row = mysql_fetch_array($result); $respected = explode(',', $row[respect]); echo '<tr><td>' echo $respected; echo '</td></tr>' echo '</table></div>'
View Replies !
Loop & Array
i have a var $category which holds an array of 3 items, all im trying to do is echo all 3 elements of the array, $categorys_result = 2; while ($categorys_result >0) { echo "$categorys[$categorys_result]<br>"; $categorys_result--; } all i get are 2 of the 3 elements i just cant get the 3rd, im assuming this is because the $categorys_result will == 0 so it doesnt display element 0.
View Replies !
A Tables Field Containing An Array
I am creating a poll/voting feature for my forum and i want to make it so that a user can only vote once per poll. So what i plan to do is store everyone username who was voted in an array and store it in a MySQL table. When someone else votes, i'll extract the array from the database, add the current voters username to the array and then write the array back to the database. Is this possible?
View Replies !
MySQL Tables Array?
Is it possible to run such a query: SHOW TABLES In php, via mysql_query and get the tables as an array? The purpose of this is so that I can run the same query on seperate tables without having to rewrite the query for each table!
View Replies !
Multidimensional Array Loop
I am trying to loop through a multidimensional array shopping cart stored in a session. I can loop through it ok but the problem is that when the page displays I have two each of the items in the cart. I am looping through with a double foreach. If I do print "$key: $value"; inside of the second foreach I get the correct display of the items in my cart but then the actual display of the items gives me two of each. Code:
View Replies !
Using A Loop To Create An Array
I am trying to populate an array with information found in a mysql database. By selecting a state they would then see every resort that contains the selected state in it's row... Kind of like a tree navigation system. Code:
View Replies !
Array Loop And Key() Function
I've created a function below, that creates two columns to display departments and the associated positions in them in a separate row from the department title. My issue is that this works fine when I have an even number of departments but not an odd one. I set a variable $new_row to determine when to create a new row and I set this in the code that creates the right hand column in the html table. My problem is that I need to determine when the array has an odd number of departments (e.g. left hand html column) when I've got to the end and then set the $new_row var. I was trying to use the key() function in an if node. To do this I've printed the key value out in ever title so I can debug the script. My issue is that the key value doesn't appear in the last odd field I've highlighted this in my code with a >>>. PHP Code:
View Replies !
Create Array With Loop
I have got a problem creating an array. I have 3 arrays with words in them. I read those words and compare them with eachother to set the final number of words and give them a score. I do this with a couple of loops and set new a variable which should become a new array. This new array (word_combi) contains the word, the number of times is was in the total list and the score. I have got the code I use below (which doesn't work)...can anyone tell me my error and point out the way to fix this? PHP Code:
View Replies !
|