182x Posted July 20, 2007 Share Posted July 20, 2007 hey guys, I have a page which displays a tables of users from a database and I on this page the user can select someone to remove from the database in order to do this they select the username from a listbox which only contains the userIds. When this userId is sent for processing I would also like to be able to send the related username without the user having to select it. How can I do this? Thank you Quote Link to comment Share on other sites More sharing options...
182x Posted July 20, 2007 Author Share Posted July 20, 2007 That may not have been clear I mean how do I send the extra piece of information, I have already got the rest setup. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2007 Share Posted July 20, 2007 if you are removing why would you need more than the ID or are you trying to echo $username". Has been Removed."; if so you should query for the data before you remove it then remove it Quote Link to comment Share on other sites More sharing options...
182x Posted July 20, 2007 Author Share Posted July 20, 2007 I also have to delete data from another table when data is deleted from the first one and the username is what links the tables Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2007 Share Posted July 20, 2007 thats a poor structure, but anyway query off the ID on table1 and use the query result to kill table 2 also Quote Link to comment Share on other sites More sharing options...
182x Posted July 20, 2007 Author Share Posted July 20, 2007 Thanks, how do you query off the first query result? Quote Link to comment Share on other sites More sharing options...
trq Posted July 20, 2007 Share Posted July 20, 2007 mysql_query(). Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2007 Share Posted July 20, 2007 <?php $q = "select Username from `table` where UserID = '$_POST['userid']; $result = mysql_query($q) or die(mysql_error()); if(mysql_num_rows($result)){ $row = mysql_fetch_array($result); $q2 = "Delete from `table2` WHERE Username = '$row['username']"; $result2 = mysql_query($q2) or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
182x Posted July 20, 2007 Author Share Posted July 20, 2007 Thats awesome, thanks for your help. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2007 Share Posted July 20, 2007 read up on database normalization because the linking key between tables is generally suppose to be an integer value that is the primary key of another table. Quote Link to comment Share on other sites More sharing options...
182x Posted July 20, 2007 Author Share Posted July 20, 2007 I will do, Just tried the code. It didn't work It first gave a syntax error because of the extra " ' " so I removed it and added braces. But then I get the the following error where jess is an actual username. Anyideas why this is happening? Unknown column 'jess' in 'where clause' Quote Link to comment Share on other sites More sharing options...
unidox Posted July 20, 2007 Share Posted July 20, 2007 I am a bit confised, what are you trying to do? Quote Link to comment 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.