PHP 다중 배열 질문 드립니다.

PHP 다중 배열 질문 드립니다.

QA

PHP 다중 배열 질문 드립니다.

본문

다중 배열을 보내고 받으려고 하고 있습니다.

50명 정도를 보내면 받는 파일쪽의 데이터의 저장 mysql에서 뒷 부분이 몇개가 저장이 되지 않는  부분이 발생하고 있습니다. 아직 초보라 다중 배열 보내는 방법에 어려움이 있습니다.

고수님들이 좋은 방법있으면 조언 부탁드립니다.

 

< 보내는 파일 : friend.php >

<?php
$stu = array('a1','a2','a3','a4','a5','a6','a7','a8','a9','a10');
$cnt=count($stu);
?>

<form action="friend_post.php" method="post" >
<table border=1>
    <tr>
        <td>이름</td>
        <?php for($i=0;$i<$cnt;$i++){ ?>
        <td><?=$stu[$i]?></td>
        <?php } ?>
    </tr>
    <tr>
    <td><?=$stu[0]?></td>
<?php 
    $a=0;
    for($i=1;$i<$cnt*$cnt+1;$i++){ 
    ?>
        <td><input type="number" name="friend[]" min="1" max="9" ></td>
        <?php if($i%$cnt==0){
            $a++;
            echo "</tr><tr>";
            echo "<td> $stu[$a] </td>";    
        } ?>
<?php }     ?>
    </table>
<div><input type="submit"></div>
</form>

 

< 받는 파일 : friend_postphp >

<?php
for($i=0; $i<count($_POST['friend']); $i++){
    $friend = $_POST['friend'];
}

foreach($friend as $value) {
    $friend .= ','.$value;
}

$txt = explode(',',$friend);
echo "<table border=1><tr>";
$cnt_a=count($txt);
$row=$cnt_a/10;
for($i=1; $i<=$cnt_a; $i++) {
    echo "<td>$txt[$i]<td>";
    if($i%$row==0) {
        echo "</tr><tr>";
    }    
}

echo "</tr></table>";
?>

이 질문에 댓글 쓰기 :

답변 2

for($i=0; $i<count($_POST['friend']); $i++){
    $friend = $_POST['friend'];
}

foreach($friend as $value) {
    $friend .= ','.$value;
}

$txt = explode(',',$friend);
 

=>

 

$txt = $_POST['friend'];

 

DB 처리하는 부분이 없네요.

답변을 작성하시기 전에 로그인 해주세요.
전체 59,590
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT