Jun20

hmm, saya seringkali lupa bagaimana caranya membuat combobox di papantulis framework (smarty + adoDB), oleh karena itu saya tulis saja langkah-langkahnya di sini supaya tidak lupa

1.Pada file ptClass buat method untuk mengambil data yang akan ditampilkan, contoh :

function getAllStudentForGrade() {
      $db= & new ptDatabase();
      $conn=$db->Connect();

       if ($conn->_errorMsg) {
            echo ‘line 65 ptAnnouncement.class.php’.$conn->_errorMsg;
            return;
      } else {
            $qr=”SELECT “.TBL_USER.”.*,
            ”.TBL_USER_STUDENTS.”.studentID,
            ”.TBL_USER_STUDENTS.”.classID,
            ”.TBL_USER_STUDENTS.”.parentID,
             ”.TBL_USER_STUDENTS.”.studentIndex
            FROM
            ”.TBL_USER.”,
            ”.TBL_USER_STUDENTS.”
            WHERE
            ”.TBL_USER.”.userID=”.TBL_USER_STUDENTS.”.userID Order By studentIndex”;

            // echo $qr;
            $rs=$conn->Execute($qr);
            $data=$rs->getArray();
            for($i=0;$i<sizeof ($data);$i++) {
                   $dataForSmartyHtmlOptions[$data[$i][’studentID’]]=$data[$i][’studentIndex’].”                   ”.$data[$i][’firstName’].” “.$data[$i][’lastName’];
            }

            return $dataForSmartyHtmlOptions;

      }

}

2. Pada file page, panggil static method di atas yang mempunyai fungsi untuk mengumpulkan data combobox, contoh :

$studentData=ptGradeSTTB::getAllStudentForGrade();

3. lalu assign data tersebut ke smarty template

$pt_smarty->assign(’studentData’,$studentData);
$pt_smarty->display(’gradeSTTBMain.html’);

4. di file smarty template tampilkan data tersebut, contoh :

<select name=”student” >
       {html_options options=$studentData selected=$studentSelect}
</select>

alhamdullilah selesai, semoga dengan begitu bila ada masalah yang sama, saya tidak perlu mencari-cari di file php papantulis yang jumlah barisnya saja bikin saya eneg, cukup cari dan lihat contohnya di sini saja

Komentar

Trackback: Use this URI to trackback this entry. Use your web browser's function to copy it to your blog posting.

Gravatar: You can have a picture at the top of each your comments by getting a Gravatar

Belum ada komentar.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.