buladex Posted November 13, 2011 Share Posted November 13, 2011 im making this tool to clean up some data from a sql database, i made a php code to list what i need, thats player name,lvl and id from table_A, the problem is i want to delete from table_A and from table_B all the results from php code , they have in common the id and as a condition the lvl must be lower then 10, it seems i cant make it delete from table_B also,please help me!! a button of the end of the page to delete all that includes same id from both tables is what im looking for! <table<?php echo $tableSet; ?>> <tr> <td width="*" align="center">Rank</td> <td width="*" align="center"><font color="#000000">Name</td> <td width="*" align="center"><font color="#000000">money</td> <td width="*" align="center"><font color="#000000">id</td> <td width="*" align="center"><font color="#000000">lvl</td> </tr> <?php $rank = mysql_query('SELECT name,money,id,level FROM table_A WHERE level < 10 ' .' ORDER by level desc LIMIT '.$limit.';'); $i=1; while ($row = mysql_fetch_array($rank)) { echo '<tr><td align="center">'.$i.'.</td> <td align="center"><font color="#0000FF">'.$row['name'].'</td> <td align="center"><font color="#0000FF">'.$row['money'].'</td> <td align="center"><font color="#0000FF">'.$row['id'].'</td> <td align="center"><font color="#FF0000">'.$row['level'].'</td> </tr> '; $i++; } ?> this is showing which player names goes to id(from table_A) i need to delete from table_a where the ids shown are lower then lvl 10(the ones result from code above) and same ids from table_b (the rank is just to show me ho is highest lvl) Quote Link to comment https://forums.phpfreaks.com/topic/251047-need-help-on-php-sql-2-table-action/ Share on other sites More sharing options...
RussellReal Posted November 13, 2011 Share Posted November 13, 2011 DELETE FROM table_A, table_B USING table_A JOIN table_B WHERE table_B.value_2 = 1 AND table_A.value = table_B.value_2; dunno if I'm understanding you right, but you should be able to work with the above Quote Link to comment https://forums.phpfreaks.com/topic/251047-need-help-on-php-sql-2-table-action/#findComment-1287799 Share on other sites More sharing options...
buladex Posted November 13, 2011 Author Share Posted November 13, 2011 before posting here i have tried many codes, the one u posted also but as u can see i also req the level <10 condition which is only in table_a so thats my biggest problem it should look like delete from table_a, table_b common ids where from table_a lvl<10 same ids, been surfing the net for almost 2 weeks and i still didnt found a solution, so i thought resulting first from table_a the ids and then a php -sql action to delete the same ids from table_b Quote Link to comment https://forums.phpfreaks.com/topic/251047-need-help-on-php-sql-2-table-action/#findComment-1287828 Share on other sites More sharing options...
RussellReal Posted November 13, 2011 Share Posted November 13, 2011 DELETE FROM table_A, table_B USING table_A JOIN table_B WHERE table_A.level < 10 AND table_A.id = table_B.user_id; ? Quote Link to comment https://forums.phpfreaks.com/topic/251047-need-help-on-php-sql-2-table-action/#findComment-1287894 Share on other sites More sharing options...
buladex Posted November 14, 2011 Author Share Posted November 14, 2011 no tested that already result is affected rows 0 its like the lvl condition doesnt aplly well,thats why im looking for php result and then delete results, in sql i didnt found a way to put a condition from a table to affect dfferent table, but if its a result in php first, i think it will affect the second table also, i really need a php guru help here!!!!!!!! and thx russell for the support! Quote Link to comment https://forums.phpfreaks.com/topic/251047-need-help-on-php-sql-2-table-action/#findComment-1288044 Share on other sites More sharing options...
RussellReal Posted November 15, 2011 Share Posted November 15, 2011 You don't need a php guru, what you're asking for is accomplished with my above query, you need to change some values to accomplish this, to relate this query to your database structure.. And if you really did need a php guru, You're probably talking to one, I just don't have the tag under my name, but that doesn't change the fact that I've been developing for 7 years.. Try the query again Quote Link to comment https://forums.phpfreaks.com/topic/251047-need-help-on-php-sql-2-table-action/#findComment-1288246 Share on other sites More sharing options...
buladex Posted November 15, 2011 Author Share Posted November 15, 2011 the thing is that all sql command didnt work before posting on forum, the above one included the only 1 had a semi result was last night it looked like this: delete from table_b where player_id = 'select player_id from table_a where level <10' after this is easy to delete from table_a, but the query above had 0,600 results on screen but i cant see if content of table_b modiffied cuz its a very large amount of data has around 700 sql pages so im turning at u now whit 1 more solution: how about on the php code above, the first one where it shows player name,lvl and id to be a delete button for every row which deletes from table_b like table_a results rank name level id button 1 test 9 999 delete <----------- from table_b Quote Link to comment https://forums.phpfreaks.com/topic/251047-need-help-on-php-sql-2-table-action/#findComment-1288317 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.