Jump to content

Interactive link with PHP?


ebotelho

Recommended Posts

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.

Link to comment
Share on other sites

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']}'");
   }
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.