ebotelho Posted April 10, 2012 Share Posted April 10, 2012 Hello. I have been developing my website and I need to create a link that moves one information from one table to the other if a certain condition is found. I have already explained what my website is about in another post, but since the focus has now changed, I've proceeded into creating a new topic. The thing is, I have two databases: one for confirmed, one for not confirmed. I want to make a link, or a button, that upon its pressing would delete an user from one table and insert the same user to the other. My idea is exactly the same as the "Topic Solved" button from phpfreaks. Is it possible to be done in PHP? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/260653-interactive-link-with-php/ Share on other sites More sharing options...
dcro2 Posted April 10, 2012 Share Posted April 10, 2012 Couldn't you just make a column `confirmed` you could set to 1 instead of having two tables? That's more like what this forum does. Quote Link to comment https://forums.phpfreaks.com/topic/260653-interactive-link-with-php/#findComment-1335898 Share on other sites More sharing options...
creata.physics Posted April 10, 2012 Share Posted April 10, 2012 dcro2's suggestion seems best fitting. You can easily toggle the status of whatever you're trying to change if you use one table with a field determining the approval status. If you use your method you will need to check the user you are approving by gathering their data from the sql table, insert that users data into a new table then delete the record from the former, here's an example: <?php if( $_GET['approve_user'] ) { $find_user = mysql_query("select * from validating_users where id = '{$_GET['approve_user']}'"); if( is_resource( $find_user ) ) { $user_found = mysql_fetch_assoc($find_user); // we found the user and he/she is valid so you can approve them mysql_query("insert into validated_users (keys) VALUES (values)"); // and remove their data from the validating table mysql_query("delete from validating_users where id = '{$user_found['id']}'"); } } Quote Link to comment https://forums.phpfreaks.com/topic/260653-interactive-link-with-php/#findComment-1335946 Share on other sites More sharing options...
ebotelho Posted April 12, 2012 Author Share Posted April 12, 2012 Couldn't you just make a column `confirmed` you could set to 1 instead of having two tables? That's more like what this forum does. I don't think that is possible due to the fact that there are many games and the players may be confirmed in more than one game at a time. Quote Link to comment https://forums.phpfreaks.com/topic/260653-interactive-link-with-php/#findComment-1336558 Share on other sites More sharing options...
chriscloyd Posted April 12, 2012 Share Posted April 12, 2012 are you moving everything to the same table layout? or will the fields be the same? Quote Link to comment https://forums.phpfreaks.com/topic/260653-interactive-link-with-php/#findComment-1336590 Share on other sites More sharing options...
chriscloyd Posted April 12, 2012 Share Posted April 12, 2012 if your fields in the table are the same you can do this <?php //include config file $old_table = ""; $new_table = ""; //get info from link like the id $id = $_GET['id']; //setup sql $Sql = "SELECT * FROM `{$old_table}` WHERE `id` = '{$id}'"; $Query = mysql_query($Sql); if ($Query){ $info = mysql_fetch_array($Query); } //set arrays for fields and values $fields = array(); $values = array(); foreach ($info as $key => $val) { $fields[] = "`{$key}`"; $values[] = "'{$val}'"; } //join fields to act as one string but seperated by , $nFields = join(",", $fields); $nValues = join(",", $values); //create sql $Copy = "INSERT INTO `{$new_table}` ({$nFields}) VALUES ({$nValues})"; $Create = mysql_query($Copy); if ($Create) { //delete old row $Delete = "DELETE FROM `{$old_table}` WHERE id = '{$id}'"; $Run = mysql_query($Delete); } else { //dont delete do something } Quote Link to comment https://forums.phpfreaks.com/topic/260653-interactive-link-with-php/#findComment-1336592 Share on other sites More sharing options...
batwimp Posted April 12, 2012 Share Posted April 12, 2012 You could just create a third table and do a one-to-many or many-to-many relationship between them. Something like: playergameID (int) player_id (int) game_id (int) confirmed (tinyint) anyotherdata (varchar, etc.) Are you familiar with relational databases? Quote Link to comment https://forums.phpfreaks.com/topic/260653-interactive-link-with-php/#findComment-1336597 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.