ต้องการให้ Array วน Loop รบกวนด้วยครับ ขอบคุณครับ

ต้องการให้มันลูป อเรย์ จากเดิม มีแค่อเรย์เดียว

mysql_select_db($database_follow, $follow);
$query_rsJob = "SELECT * FROM tb_job WHERE project_id = '$project_id'";
$rsJob = mysql_query($query_rsJob, $follow) or die(mysql_error());
$row_rsJob = mysql_fetch_assoc($rsJob);
$totalRows_rsJob = mysql_num_rows($rsJob);

$job = $row_rsJob['job_name'] ;
$jobStart = explode("-",$row_rsJob['job_start']);
$jobEnd = explode("-",$row_rsJob['job_end']);


//ของเดิม
$definitions['planned']['phase'][0]['name'] = $row_rsJob['job_name'] ;
$definitions['planned']['phase'][0]['start'] = mktime(0,0,0,$jobStart[1],$jobStart[2],$jobStart[0]);
$definitions['planned']['phase'][0]['end'] = mktime(0,0,0,$jobEnd[1],$jobEnd[2],$jobEnd[0]);


ปรับโคด ข้างบน เป็นแบบข้างล่าง แต่ผลยังเพี้ยน(คือ ลูป แต่ของเดิม อเรย์อื่น

เช่น อเร 0  = A  1 = B  2 = C แทนทีจะออก A B C แต่ออก A A A) ไม่แน่ใจ ว่า ใส่ อะไรผิดอะไร รบกวนด้วยครับ ขอบคุณครับ

 

//แก้ไขใหม่

$n=0; do { $n ++ ;

$definitions['planned']['phase'][$n]['name'] = $row_rsJob['job_name'] ;
$definitions['planned']['phase'][$n]['start'] = mktime(0,0,0,$jobStart[1],$jobStart[2],$jobStart[0]);
$definitions['planned']['phase'][$n]['end'] = mktime(0,0,0,$jobEnd[1],$jobEnd[2],$jobEnd[0]);

} while ($row_rsJob = mysql_fetch_assoc($rsJob));

23 ธ.ค. 2551 4 3,417

ลองทำความเข้าใจกับแบบนี้ดู     

while ($row = @mysql_fetch_array($query, MYSQL_ASSOC)) {
  // เอาข้อมูลที่แ่านได้ใส่ array
  $recArr[] = $row;
}


ทดสอบผลลัพท์ เอาแค่ array ที่ได้ไปจัดการต่อ

print_r($recArr);
#1

ขอบคุณครับ อาจารย์ แต่ผมนำไปประยุกต์ไม่เป็น ทดสอบแล้ว มันออก ประมาณนี้ Array ( [0] => Array ( [user_id] => 957 [user_title] => นางสาว [user_name] => ชลอลักษณ์ [user_lastname] => ธรรมผล [user_nickname] => ชลอ [user_position] => ผู้อำนวยการกลุ่มงานบริหารทั่วไป [user_c] => [user_login] => 957 [user_password] => 957 [group_id] => 1 [level_id] => 2 [user_address] => [user_mobile] => [user_email] => [user_comment] => [pic] => ) [1] ..... ผมลอง แบบนี้ก้อไม่น่าใช่ while ($row = @mysql_fetch_array($rsJob, MYSQL_ASSOC)) { // เอาข้อมูลที่แ่านได้ใส่ array $recArr[] = $row; } $definitions['planned']['phase'][$row]['name'] = $row_rsJob['job_name'] ; $definitions['planned']['phase'][$row]['start'] = mktime(0,0,0,$jobStart[1],$jobStart[2],$jobStart[0]); $definitions['planned']['phase'][$row]['end'] = mktime(0,0,0,$jobEnd[1],$jobEnd[2],$jobEnd[0]); ยังไงก้อรบกวนด้วยครับ ขอบคุณครับ
#2

กรรม

ลองศึกษาเกี่ยวกับ Array ดูหน่อยครับ มันช่วยงานได้มากเลยครับ น่าเรียนรู้ไว้
#3

ขอบคุณครับ กำลังศึกษาทำความเข้าใจ ปกติไม่ค่อยได้เขียนแบบอเรย์
#4
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^