본문 바로가기

Web/PHP

파일 디비에서의 위치변경(순서변경)

<script language='javascript'>
function ChangeCheck(obj)
{
    with(obj)
    {
        var slt1 = elements['mode'].selectedIndex;
        var slt2 = elements['mode2'].selectedIndex;

        if(slt1==slt2) { alert('두개의 위치가 동일합니다.'); return false;}

        submit();
    }
}
</script>

<table cellspacing='0' cellpadding='0' border='0' width='95%' align='center'>
<tr>
    <td>
<form method='post' action='area_process.php?psMode=CHANGE' name='frm_write' enctype='multipart/form-data' style='border:0;margin:0' onSubmit='return ChangeCheck(this)'>
<?php
if($aFile)
{
    echo '<select name="mode" class=input>';
    foreach($aFile as $ix => $v)
    {
        $v = str_replace('|',' ',$v);
        echo "<option value=$ix>$v";
    }
    echo '</select> 와 ';

    echo '<select name="mode2" class=input>';
    foreach($aFile as $ix => $v)
    {
        $v = str_replace('|',' ',$v);
        echo "<option value=$ix>$v";
    }
    echo '</select> 의 위치를 ';
}
?>
<input type='submit' value=' 바꾸기 ' class='inputbtn' />
</form>
</td>
</tr>
</table>

---------------------------------------------------------- process
<?php
case( 'CHANGE' ):
        
    extract($_POST);
    $aArea = file('./data/area.cgi');
    $first = $aArea[$mode];
    $last = $aArea[$mode2];
    for($i=0; $i<count($aArea); ++$i)
    {
        if($mode == $i)
        {
            $aArea[$i] = $last;
        }
        else if($mode2 == $i)
        {
            $aArea[$i] = $first;
        }
    }
        
//        $objCommon->printR($aArea);

    //    exit;

    $fp = fopen("./data/area.cgi", w);        
        foreach($aArea as $index => $value)
        {
            if($_GET[no]!=$index) fwrite($fp, $value);
        }
        fclose($fp);
         $objCommon->go("./{$sPage}_list.php");

break;