|
|
|
ขอสอบถามเรื่องการรับค่าแบบ Array ซ้อน Array หน่อยค่ะ |
|
|
|
|
|
|
|
ขอสอบถามค่ะ คือหนูต้องการนำค่ามาใส่ในArray 2 ตัว ให้ได้แบบนี้ค่ะ
Code
subj[0] =>
[class_group] => 0
[timeslot_no] => 1
[subject_id] => 321
[teacher_name] => 2
[major_year] => 6602
[major_name] => 2
[labroom_name] => 1
[duration] => 3
subj[1]=>
[class_group] => 1
[timeslot_no] => 2
[subject_id] => 322
[teacher_name] => 1
[major_year] => 6603
[major_name] => 1
[labroom_name] => 1
[duration] => 3
แต่ค่าที่ได้มันกลับเหมือนกันที้งสองตัวเลยค่ะ หนูเขียนผิดตรงไหนหรือเปล่าค่ะ ช่วยแนะนำด้วยค่ะ ขอบคุณมาก
ไฟล์ฟอร์ม
Code (PHP)
<form name="form1" method="post" action="setsubj.php">
<table>
<tr><td>Class group :<input type="text" name="class_group[]" value="" />
subject ID :<input type="text" name="subject_id[]" value="" />
teacher name :<input type="text" name="teacher_name[]" value="" />
labroom Name :<input type="text" name="labroom_name[]" value="" />
Major Name :<input type="text" name="major_name[]" value="" />
Major year :<input type="text" name="major_year[]" value="" />
Duration :<input type="text" name="Duration[]" value="" /></td></tr>
<tr><td><input type="submit" name="submit" value="OK" /></td></tr>
</table>
</form>
ไฟล์ที่ส่งข้อมูลมา
<?php
class subj {
var $class_group;
var $timeslot_no;
var $subject_id;
var $teacher_name;
var $major_year;
var $major_name;
var $labroom_name;
var $duration;
function subj ($class_group=0,$timeslot_no=0,$subject_id=0,$teacher_name=0,$major_year=0,$major_name=0,$labroom_name=0,$duration=0) {
$this->class_group = $class_group;
$this->timeslot_no = $timeslot_no;
$this->subject_id = $subject_id;
$this->teacher_name = $teacher_name;
$this->major_year = $major_year;
$this->major_name = $major_name;
$this->labroom_name = $labroom_name;
$this->duration= $duration;
}
}
$year = $_POST['year'];
$semester = $_POST['semester'];
if($_POST!=$_POST['year']or $_POST!=$_POST['semester']){
for($i=0;$i<count($_POST);$i++){
$class_group = $_POST['class_group'];
$subject_id = $_POST['subject_id'];
$teacher_name = $_POST['teacher_name'];
$labroom_name = $_POST['labroom_name'];
$major_name = $_POST['major_name'];
$major_year = $_POST['major_year'];
$duration = $_POST['duration'];
}
}
for($j=0;$j<$i;$j++){
$chro['$j'] = new subj($class_group['$j'],$timeslot_no['$j']=1,$subject_id['$j'],$teacher_name['$j'],$labroom_name['$j'],$major_name['$j'],$major_year['$j'],$duration['$j']);
$algo = new algo();
$algo->population = array($chro['$j'],$chro['$j'-'$i']);
}
?>
Tag : PHP
|
|
|
|
|
|
Date :
2012-12-02 20:37:07 |
By :
nok |
View :
964 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตัวย่างการรับค่า(PHP)
<?php
if(!empty($_POST['class_group'])){
for($i=0;$i<count($_POST['class_group']);$i++){
echo $_POST['class_group'][$i]."<br />";
echo $_POST['subject_id'][$i]."<br />";
echo $_POST['teacher_name'][$i]."<br />";
echo $_POST['labroom_name'][$i]."<br />";
echo $_POST['major_name'][$i]."<br />";
echo $_POST['Duration'][$i]."<br />";
echo "<hr />";
}
}
?>
|
|
|
|
|
Date :
2012-12-03 08:41:18 |
By :
mangkunzo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากค่ะ
|
|
|
|
|
Date :
2012-12-03 13:41:02 |
By :
nok |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|