Forum Sementara Putera.com

Bersama kita perkemaskan forum ini sementara forum asal dalam pemulihan.

Forum putera dah kembali. Masalah sudah berjaya diselesaikan. Sila lawati http://forum.putera.com/tanya


    PHP - Moving data from one table to another table

    Share

    damia
    Ahli Baharu
    Ahli Baharu

    Number of posts : 12
    Registration date : 25/03/2009

    PHP - Moving data from one table to another table

    Post by damia on Wed Mar 25, 2009 2:00 am

    saya ade senarai data dlm satu table,saya nak move kan salah satu data ke dalam lg satu table.

    contoh:

    table waiting list yg tunggu utk di approve kan.bila saya click approve, data yg di approved tu akan masuk ke dlm table lain.so data dlm table yg pertama td dah takde.

    please tolong saya..saya dh dapat cari coding die.tp tak tau pulak mane nak letak coding tu.

    if($_GET['a'] == 'process' && $_POST['approve']){

    $idlist = $_POST['approve'];

    if($_POST['approve_sub']){
    $action = 'approve';
    }elseif($_POST['reject']){
    $action = 'reject';
    }

    ?>
    <form action="<?php echo $_SERVER['PHP_SELF'] ?>?a=<?php echo $action; ?>" method="post">
    <center>
    You are about to <?php echo $action; ?> the following applications:<br />
    <table border="5" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="90%" id="AutoNumber2" bgcolor="#C0C0C0">
    <tr>
    <td width=17.7% align=center bgcolor="#FFFFCC"><b>Name</b></td>
    <td width=14.8% align=center bgcolor="#FFFFCC"><b>Country</b></td>
    <td width=8.1% align=center bgcolor="#FFFFCC"><b>Location</b></td>
    </tr>
    <?php
    foreach( $idlist as $key => $value){
    $row = mysql_fetch_array(mysql_query("SELECT * FROM `apps` WHERE `id`='" . $value . "'")) or die(mysql_error());
    echo " <tr>";
    echo " <td align=center><input type=\"hidden\" value=\"" . $row['id'] . "\" name=\"approve[]\" />" . $row['alias'] . "</td>";
    echo " <td align=center>" . $row['Name'] . "</td>";
    echo " <td align=center>" . $row['Country'] . "</td>";
    echo " <td align=center>" . $row['Location'] . "</td>";
    echo " </tr>";
    }
    ?>
    <tr>
    <td align=center bgcolor="#FFFFCC" colspan='5'><input type="submit" value="Confirm" name="confirm" /> <input type="submit" value="Cancel" name="cancel" /></td>
    </tr>
    </table>
    </center>
    </form>
    <?php
    }elseif($_GET['a'] == 'approve' && $_POST['approve']){

    $idlist = $_POST['approve'];

    if($_POST['cancel']){
    $cancel = 'true';
    }elseif($_POST['confirm']){
    foreach( $idlist as $key => $value){
    $copy = mysql_fetch_array(mysql_query("SELECT * FROM `apps` WHERE `id`='" . $value . "'")) or die(mysql_error());
    // ^^ SELECT THE DATA TO BE COPIED ^^

    @mysql_query("INSERT INTO `approved` (`Name`, `Country`, `Location`) VALUES('" . $copy['Name'] . "', '" . $copy['Country'] . "', '" . $copy['Location'] . "')") or die(mysql_error());
    // ^^ COPY THE DATA ^^
    //CHANGE 'approved' INTO THE NAME OF THE TABLE CONTAINING THE APPROVED APPLICATIONS
    //ADD ANY OTHER FIELDS THAT ARE NECESSARY TO THE LISTS

    @mysql_query("DELETE FROM `apps` WHERE `id`='" . $value . "'") or die(mysql_error());
    // ^^ DELETE THE OLD DATA ^^
    }
    echo "Applications successfully approved.";
    }

    }elseif($_GET['a'] == 'reject' && $_POST['approve']){

    $idlist = $_POST['approve'];

    if($_POST['cancel']){
    $cancel = 'true';
    }elseif($_POST['confirm']){
    foreach( $idlist as $key => $value){
    @mysql_query("DELETE FROM `apps` WHERE `id`='" . $value . "'") or die(mysql_error());
    // ^^ DELETE THE REJECTED APPLICATION DATA ^^
    }
    echo "Applications successfully rejected.";
    }

    }
    if(!$_GET['a'] || $cancel || !$_POST['approve']){
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF'] ?>?a=process" method="post">
    <center>
    <table border="5" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="90%" id="AutoNumber2" bgcolor="#C0C0C0">
    <tr>
    <td align=center bgcolor="#FFFFCC"></td>
    <td width=17.7% align=center bgcolor="#FFFFCC"><b>Name</b></td>
    <td width=14.8% align=center bgcolor="#FFFFCC"><b>Country</b></td>
    <td width=8.1% align=center bgcolor="#FFFFCC"><b>Location</b></td>
    </tr>
    <?php
    $result = mysql_query("SELECT * FROM `apps`") or die(mysql_error());
    while($row = mysql_fetch_array($result)){
    echo " <tr>";
    echo " <td align=center><input type=\"checkbox\" value=\"" . $row['id'] . "\" name=\"approve[]\" /></td>";
    echo " <td align=center>" . $row['Name'] . "</td>";
    echo " <td align=center>" . $row['Country'] . "</td>";
    echo " <td align=center>" . $row['Location'] . "</td>";
    echo " </tr>";
    }
    ?>
    <tr>
    <td align=center bgcolor="#FFFFCC" colspan='6'><input type="submit" value="Approve" name="approve_sub" /> <input type="submit" value="Reject" name="reject" /></td>
    </tr>
    </table>
    </center>
    </form>
    <?php
    }

    chanhonam
    Ahli Baharu
    Ahli Baharu

    Number of posts : 1
    Registration date : 04/03/2009

    Re: PHP - Moving data from one table to another table

    Post by chanhonam on Fri Mar 27, 2009 10:32 am

    ni aku bg die punye code mysql shj k.. just link kan dengan ko punye form je then mende tu akan function. slmt mencuba

    Code:

    if($_POST['accept']){
    $sql_accept = mysql_query("SELECT * FROM <table sementara> WHERE id='<id user yg nk di accept>'");
    $row_acceptl = mysql_fetch_assoc($sql_accept);

    $sql_add = mysql_query("INSERT INTO <table approve> (fieldname)
                          VALUES (nilai2 untuk dimasukkn dlm table baru)");

    $sql_del = mysql_query("DELETE FROM <table sementara> WHERE id = '<id user yg nak dibuang dr table sementara tu>'");

    if(($sql_del) && ($sql_add)){
      echo "Maklumat berjaya diluluskan"
    }

    }
    elseif($_POST['rejected']){
      $sql_rejected = mysql_query("DELETE FROM <table sementara> WHERE id = '<id user sementara yg nk di delete>'");

    }

    //habis la setakat tu sahaja logik code untuk kerja yg ingin ko buat tu

    Kuzie
    Ahli Baharu
    Ahli Baharu

    Gender : Male Number of posts : 125
    Age : 32
    Location : eVeRyWhErE
    Registration date : 13/02/2009

    Re: PHP - Moving data from one table to another table

    Post by Kuzie on Sun Mar 29, 2009 7:25 pm

    chanhonam....bagi list detail kat bawah ni:

    1)Bagi semua code form sebelum approve dan selepas approve..
    2)Bagi die punye MySQL table untuk kiteorang wat demo table supaya sama dgn ko punye table(kalau boleh dengan record sekali la supaya result sama dgn apa yg ko hendak)

    damia
    Ahli Baharu
    Ahli Baharu

    Number of posts : 12
    Registration date : 25/03/2009

    Re: PHP - Moving data from one table to another table

    Post by damia on Mon Mar 30, 2009 1:31 pm

    ni form sebelum approve

    <form id="waitinglist" name="form1" method="post" action="">
    <table width="786" border="0" align="center">
    <tr>
    <td colspan="6">Futsal Court </td>
    </tr>
    <tr>
    <td bgcolor="#252525" class="style21"><div align="center">No</div></td>
    <td bgcolor="#252525" class="style21"><div align="center">Name </div></td>
    <td bgcolor="#252525" class="style21"><div align="center">Date</div></td>
    <td bgcolor="#252525" class="style21"><div align="center">Start Time</div></td>
    <td bgcolor="#252525" class="style21"><div align="center">End Time</div></td>
    <td bgcolor="#252525" class="style21">&nbsp;</td>
    </tr>
    <tr>
    <td width="38" bgcolor="#FFFFFF"><div></div></td>
    <td width="188" bgcolor="#FFFFFF"><div></div></td>
    <td width="155" bgcolor="#FFFFFF"><div></div></td>
    <td width="153" bgcolor="#FFFFFF"><div></div></td>
    <td width="146" bgcolor="#FFFFFF"><div></div></td>
    <td width="80" bgcolor="#FFFFFF"><div>Approved</div></td>
    </tr>
    </table>
    </form>

    ni form selepas approve

    <form id="approvedlist" name="form1" method="post" action="">
    <table width="786" border="0" align="center">
    <tr>
    <td colspan="6">Futsal Court </td>
    </tr>
    <tr>
    <td bgcolor="#252525" class="style21"><div align="center">No</div></td>
    <td bgcolor="#252525" class="style21"><div align="center">Name </div></td>
    <td bgcolor="#252525" class="style21"><div align="center">Date</div></td>
    <td bgcolor="#252525" class="style21"><div align="center">Start Time</div></td>
    <td bgcolor="#252525" class="style21"><div align="center">End Time</div></td>
    <td bgcolor="#252525" class="style21">&nbsp;</td>
    </tr>
    <tr>
    <td width="38" bgcolor="#FFFFFF"><div></div></td>
    <td width="188" bgcolor="#FFFFFF"><div></div></td>
    <td width="155" bgcolor="#FFFFFF"><div></div></td>
    <td width="153" bgcolor="#FFFFFF"><div></div></td>
    <td width="146" bgcolor="#FFFFFF"><div></div></td>
    </tr>
    </table>
    </form>

    sya wat table utk waiting list and approved list asing2 tp datanya sama.yg ni utk futsal court sahaja.

    first_user_name varchar(20) (not null)
    last_user_name varchar(20) (not null)
    matrix_no varchar(20) (not null) primary key
    fac_dep varchar(50) (not null)
    phone_no varchar(20) (not null)
    email varchar(40) (not null)
    name_event varchar(50) (not null)
    book_date date (not null)
    start_time time (not null)
    end_time time (not null)
    fut_court_type varchar(20) (not null)
    fut_court_id varchar(20) (not null) primary key

    record

    first_user_name Nur Damia
    last_user_name Zainol Abidin
    matrix_no 2006837655
    fac_dep ftmsk
    phone_no 0139667676
    email applenclove@gmail.com
    name_event riadah
    book_date 2000-04-12
    start_time 09:00:00
    end_time 12:00:00
    fut_court_type Futsal A
    fut_court_id FA21

    Sponsored content

    Re: PHP - Moving data from one table to another table

    Post by Sponsored content Today at 4:53 pm


      Current date/time is Sat Dec 10, 2016 4:53 pm