Thursday, July 26, 2012

How to Inherit A Model from Another Model in CodeIgniter

 ជាដំបូង​យើងត្រួវបង្កើតតាមការណែនាំដូចខាងក្រោម:
 
 1/. sout_model.php  
 
class sout_model extends CI_Model {
    function __construct() {
        parent::__construct();
    }

    function get() {
        return 'Inherit Mode';
    }
}
 
2/.  saret_model.php
 
include('sout_model.php');
class saret_model extends sout_model {
    function __construct() {
        parent::__construct();
    }

    function get_saret() {
        return parent::get();
    }
}
 
 
ក្រោយមកយើងត្រូវបង្កើត Controller ដូចខាងក្រោម: 
 
3/.human.php
 
class Human extends CI_Controller {     
    function __construct(){
        parent::__construct();
        $this->load->model('saret_model');
    }       

    function get_saret() {
        $data['human'] = $this->saret_model->get_saret();
        $this->load->view('saret/saret_interface', $data);
    }
}
 
 
 

How to create pagination with codeigniter

In Controller:

  $this->pagingConfig = array();
  $this->pagingConfig['base_url'] = 'URL';
  $this->pagingConfig['total_rows'] = 0;//TOTAL ROWS
  $this->pagingConfig['cur_page'] = 0;//CURRENT PAGE NUMBER
  $this->pagingConfig['per_page'] = 0;//YOUR RESULTS PER PAGE
  $this->pagingConfig['num_links'] = 2;//NUMBER OF LINKS BEFORE
 //AND AFTER CURRENT PAGE IF ON PAGE ONE WILL SHOW 4 PAGES AFTERWARDS
 //IF YOU HAVE ENOUGH RESULTS TO FILL THAT MANY
  $this->pagingConfig['first_link'] = "<< First";
  $this->pagingConfig['last_link'] = "Last >>";
  $this->pagingConfig['full_tag_open'] = "<div class='pagination'>";
  $this->pagingConfig['full_tag_close'] = "</div>";
  $this->pagingConfig['last_tag_open'] = "";
  $this->pagingConfig['first_tag_close'] = "";
  $this->pagingConfig['anchor_class'] = "page";
  $this->pagination->initialize($this->pagingConfig);
  $strPaging = $this->pagination->create_links();
 
 
EXTENDED PAGINATION LIBRARY CALL
 
function create_links()
{
  // EDIT: ADDED THIS BECAUSE COULDN'T SEEM TO SET THIS ANYWHERE ELSE
  if ($this->anchor_class != '')
  {
     $this->anchor_class = 'class="'.$this->anchor_class.'" ';
  }

  // If our item count or per-page total is zero there is no need to continue.
  if ($this->total_rows == 0 OR $this->per_page == 0)
  {
     return '';
  }

  // Calculate the total number of pages
  $num_pages = ceil($this->total_rows / $this->per_page);

  // Is there only one page? Hm... nothing more to do here then.
  if ($num_pages == 1)
  {
     return '';
  }

  // Determine the current page number.
  $CI =& get_instance();

  if ($CI->config->item('enable_query_strings') === TRUE OR 
$this->page_query_string === TRUE)
  {
     if ($CI->input->get($this->query_string_segment) != 0)
     {
        $this->cur_page = $CI->input->get($this->query_string_segment);

        // Prep the current page - no funny business!
        $this->cur_page = (int) $this->cur_page;
     }
  }
  else
  {
     if ($CI->uri->segment($this->uri_segment) != 0)
     {
        $this->cur_page = $CI->uri->segment($this->uri_segment);

        // Prep the current page - no funny business!
        $this->cur_page = (int) $this->cur_page;
     }
  }

  $this->num_links = (int)$this->num_links;

  if ($this->num_links < 1)
  {
     show_error('Your number of links must be a positive number.');
  }

  if ( ! is_numeric($this->cur_page))
  {
     $this->cur_page = 1;
  }

  // Is the page number beyond the result range?
  // If so we show the last page
  if ($this->cur_page > $this->total_rows)
  {
     $this->cur_page = ($num_pages - 1);
  }

  // EDIT: DON'T NEED THIS THE WAY I'VE CHANGED IT
  // $uri_page_number = $this->cur_page;
  // $this->cur_page = floor(($this->cur_page/$this->per_page) + 1);

  // EDIT: START OF MODIFIED START AND END TO WORK HOW I WANT
  $totalLinks = ($this->num_links*2)+1;
  if($totalLinks > ($this->total_rows/$this->per_page))
  {
     $totalLinks = ceil($this->total_rows/$this->per_page);
  }
  //first page
  if($this->cur_page == 1)
  {
     $start = 1;
     $end = $start + $totalLinks - 1;
  }
  //middle pages
  elseif($this->cur_page + $this->num_links <= $num_pages && 
 $this->cur_page - $this->num_links > 0)
  {
     $start = $this->cur_page - $this->num_links;
     $end = $this->cur_page + $this->num_links;
  }
  //last couple of pages
  elseif(($this->cur_page + $totalLinks) > $num_pages)
  {
     $start = $num_pages - $totalLinks + 1;
     $end = $num_pages;
     //check to see if this is in the first half of links so it doesn't jump the paging
     if($this->cur_page <= $this->num_links)
     {
        $start = 1;
        $end = $start + $totalLinks - 1;
     }
  }
  //first couple of pages
  elseif(($this->cur_page - $totalLinks) < 1)
  {
     $start = 1;
     $end = $start + $totalLinks - 1;
  }
  // EDIT: END OF MODIFIED START AND END TO WORK HOW I WANT

  // EDIT: CODEIGNITERS BASE PAGING SETUP SEE ABOVE FOR MY CHANGES
  // $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page -
 ($this->num_links - 1) : 1;
  // $end   = (($this->cur_page + $this->num_links) < $num_pages) ?
$this->cur_page + $this->num_links : $num_pages;

  // Is pagination being used over GET or POST?  If get, add a per_page query
  // string. If post, add a trailing slash to the base URL if needed
  if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
  {
     $this->base_url = rtrim($this->base_url).'&amp;'.$this->query_string_segment.'=';
  }
  else
  {
     $this->base_url = rtrim($this->base_url, '/') .'/';
  }

  // And here we go...
  $output = '';

  // Render the "First" link
  // EDIT: CHANGED TO ALWAYS SHOW FIRST LINK AT LEAST
  if  ($this->first_link !== FALSE AND $this->cur_page != 1)
  {
     $first_url = ($this->first_url == '') ? $this->base_url."1" : $this->first_url;
     $output .= $this->first_tag_open.'<a '.$this->anchor_class.'href=
"'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
  }
  else
  {
     $output .= $this->cur_tag_open.$this->first_link.$this->cur_tag_close;
  }

  // Render the "previous" link
  // EDIT: CHANGED TO ALWAYS SHOW PREVIOUS LINK AT LEAST
  if  ($this->prev_link !== FALSE AND $this->cur_page != 1)
  {
     $i = $this->cur_page-1;

     if ($i == 0 && $this->first_url != '')
     {
        $output .= $this->prev_tag_open.'<a  '.$this->anchor_class.
 'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
     }
     else
     {
        $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix;
        $output .= $this->prev_tag_open.'<a  '.$this->anchor_class.
 'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
     }

  }
  else
  {
     $output .= $this->cur_tag_open.$this->prev_link.$this->cur_tag_close;
  }

  // EDIT: CHANGED THIS TO ALWAYS SHOW ALL LINKS WANTED EVEN IF ON FIRST PAGE
  // Render the pages
  if ($this->display_pages !== FALSE)
  {
     // Write the digit links
     for ($loop = $start; $loop <= $end; $loop++)
     {
        // EDIT: DON'T NEED THIS THE WAY I'VE CHANGED IT
        // $i = ($loop * $this->per_page) - $this->per_page;

        if ($loop >= 0)
        {
           if ($this->cur_page == $loop)
           {
              $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page
           }
           else
           {
              $n = ($loop == 0) ? '0' : $loop;

              if ($n == '' && $this->first_url != '')
              {
                 $output .= $this->num_tag_open.'<a  '.$this->
 anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
              }
              else
              {
                 $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix;

                 $output .= $this->num_tag_open.'<a  '.$this->anchor_class.
 'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
              }
           }
        }
     }
  }

  // Render the "next" link
  // EDIT: CHANGED TO ALWAYS SHOW NEXT LINK AT LEAST
  if ($this->next_link !== FALSE AND $this->cur_page < $num_pages)
  {
     $output .= $this->next_tag_open.'<a  '.$this->anchor_class.'href="' 
.$this->base_url.$this->prefix.($this->cur_page+1).$this->suffix.'">' 
.$this->next_link.'</a>'.$this->next_tag_close;
  }
  else
  {
     $output .= $this->cur_tag_open.$this->next_link.$this->cur_tag_close;
  }

  // Render the "Last" link
  // EDIT: CHANGED TO ALWAYS SHOW LAST LINK AT LEAST
  if ($this->last_link !== FALSE AND $this->cur_page != $num_pages)
  {
     $i = (($num_pages));
     $output .= $this->last_tag_open.'<a  '.$this->anchor_class. 
'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.'</a>' 
.$this->last_tag_close;
  }
  else
  {
     $output .= $this->cur_tag_open.$this->last_link.$this->cur_tag_close;
  }

  // Kill double slashes.  Note: Sometimes we can end up with a double slash
  // in the penultimate link so we'll kill all double slashes.
  $output = preg_replace("#([^:])//+#", "\\1/", $output);

  // Add the wrapper HTML if exists
  $output = $this->full_tag_open.$output.$this->full_tag_close;

  return $output;
}
  
 
 
 
Note:
 
 
I have created image gallery using CodeIgniter default pagination. The images are came from db and each page have 16 images.
Recently my customer ask me to put 32 images per each page other than the first page. This means that on the first page it only have 16 images and the other pages come after that have 32 images per page. So I change the code little bit and get the result as he asked.
 
 
if (((int)$this->uri->segment(3)) > 16)
{
    $config['per_page'] = 32;
}
else
{
    $config['per_page'] = 16;
}

$this->pagination->initialize($config);
 

Sunday, July 22, 2012

Cleaner URLs CodeIgniter

Now we can clean up the urls by rewriting them without index.php. This is most easily done with an htacces file. Create or open the file /var/www/example.com/html/.htaccess and add the following:


RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]

Thursday, July 12, 2012

Sample code C++ Score Student Management


You just copy this source code and you can run it:

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
const size=100;
class Student{
private:
int id;
char name[25];
char sex[7];
      char address[25];
char grade[10];
float mat, phy, khmer;
float total, avg;
int rank;
public:
Student(){
static int autoNum=1;
id =autoNum;
            autoNum++;
}
void read(){
cout<<"ID\t"<<getID();cout<<endl<<endl;
  cout<<"Name\t"; gets(name);cout<<endl;
cout<<"Sex\t";  gets(sex); cout<<endl;
            cout<<"Address\t"; gets(address); cout<<endl;
cout<<"Mat\t"; cin>>mat;cout<<endl;
        cout<<"Phy\t";cin>>phy;cout<<endl;
            cout<<"Khmer\t";cin>>khmer;cout<<endl;
total=mat+phy+khmer;
avg=total/3.0; grad();
}
void grad(){
int avg;
avg = total/3.0;
if(avg > 90){
strcpy(grade,"A");
}else if(avg > 80){
strcpy(grade,"B");
}else if(avg > 70){
strcpy(grade,"C");
}else if(avg > 60){
  strcpy(grade,"D");
}else if(avg > 50){
strcpy(grade,"E");
}else{
strcpy(grade,"F");
}
}
void tableHeader(){
      cout<<"ID\tName\tSex\tAddress\tMat\tPhy\tKhmer\tTotal"
<<"\tAverage\tGrade\tRank"<<endl;
}
void display(){
      cout<<getID()<<"\t"<<name<<"\t"<<sex<<"\t"<<address<<"\t"<<mat<<"\t"
            <<phy<<"\t"<<khmer<<"\t"<<total<<"\t"<<avg<<"\t"
<<grade<<"\t"<<rank<<endl;
}
void setData(Student obj){
      this->id=obj.id;
strcpy(this->name, obj.name);
strcpy(this->sex, obj.sex);
          strcpy(this->address,obj.address);
stpcpy(this->grade,obj.grade);
this->mat=obj.mat;
this->phy=obj.phy;
this->khmer=obj.khmer;
this->total=obj.total;
this->avg=obj.avg;
}
void insertName(){
cout<<"Input New Name: "; gets(name);
}
void insertSex(){
cout<<"Input New Sex: "; gets(sex);
}
      void insertAddress(){
      cout<<"Address: ";gets(address);
      }
      double insertMath(){
      cout<<"Math:";cin>>mat;
            return mat;
      }
      double insertPhy(){
      cout<<"Phy:";cin>>phy;
            return phy;
      }
      double insertKhmer(){
      cout<<"Khmer:";cin>>khmer;
            return khmer;
      }
void insertScore(int value,int id_num){
            double math,ph,kh;
            if(value==1 && id==id_num){
            math=insertMath();
               total=math+phy+khmer;
          avg=total/3.0;
grad();
            }else if(value==2 && id==id_num){
            ph=insertPhy();
               total=mat+ph+khmer;
          avg=total/3.0;
grad();
            }else if(value==3 && id==id_num){
            kh=insertKhmer();
            total=mat+phy+kh;
          avg=total/3.0;
grad();
            }

}
          void insertScores(){
      cout<<"Mat: "; cin>>mat;
cout<<"Phy: "; cin>>phy;
cout<<"Khmer: "; cin>>khmer;
total=mat+phy+khmer;
          avg=total/3.0;
grad();
}
void setRank(int n){
rank=n;
}
float getTotal(){
return total;
}
float getAverage(){
return avg;
}
float getID(){
return id;
}
char *getName(){
return name;
}
char *getSex(){
return sex;
}
      char *getAddress(){
      return address;
      }
float getMat(){
return mat;
}
float getPhy(){
return phy;
}
float getKhmer(){
return khmer;
}
char *getGrade(){
return grade;
}
int getRank(){
return rank;
}

};
void insert(Student obj[], int d){
obj[d].read();
}
void rank(Student obj[],int n);
void sortByAverage(Student obj[], int n);
void sortByID(Student obj[], int n);
void sortByName(Student obj[], int n);
void searchByID(Student obj[], int n);
void searchByName(Student obj[], int n);
void searchByRank(Student obj[], int n);
void deleteRecord(Student obj[], int d, int n);
void Update(Student stu[], int n);

   void rank(Student obj[],int n){
int rank=1;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(obj[i].getTotal()<obj[j].getTotal()){
++rank;
}
}
obj[i].setRank(rank);
rank=1;
         }
}
void sortByAverage(Student stu[], int n){
int i, j, ord;
Student stuTemp;
cout<<endl<<"1.Sort by acending"<<endl;
cout<<"2.Sort by descending";cin>>ord;
if(ord == 1) {
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
if(stu[i].getAverage() < stu[j].getAverage()){
stuTemp = stu[i];
stu[i] = stu[j];
stu[j] = stuTemp;
}
}
if(ord==2){
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
if(stu[i].getAverage() > stu[j].getAverage()){
stuTemp = stu[i];
stu[i] = stu[j];
stu[j] = stuTemp;
}
}
}
void sortByID(Student stu[], int n){
int i, j, ord;
Student stuTemp;
cout<<"1.Sort by ascending"<<endl;
cout<<"2.Sort by descending"; cin>>ord;
if(ord == 1) {
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
if(stu[i].getID() > stu[j].getID()){
stuTemp = stu[i];
stu[i] = stu[j];
stu[j] = stuTemp;
}
}
if(ord==2){
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
if(stu[i].getID() < stu[j].getID()){
stuTemp = stu[i];
stu[i] = stu[j];
stu[j] = stuTemp;
}
}
   }
void sortByName(Student stu[], int n){
int ord;
Student stuTemp;
cout<<"1.Sort by ascending"<<endl;
cout<<endl<<"2.Sort by descending"; cin>>ord;
if(ord==1){
for(int i=0; i<n-1; i++)
for(int j=i+1; j<n; j++)
if(strcmp(stu[i].getName(), stu[j].getName()) > 0){
stuTemp = stu[i];
stu[i] = stu[j];
stu[j] = stuTemp;
}
}

if(ord==2){
for(int i=0; i<n-1; i++)
for(int j=i+1; j<n; j++)
                  if(strcmp(stu[i].getName(), stu[j].getName()) < 0){
stuTemp = stu[i];
stu[i] = stu[j];
stu[j] = stuTemp;
}
}
   }
   void searchByID(Student stu[], int n){
int search; char ch; int j;
         cout<<endl<<"Search By ID: "; cin>>search;
for(int i=0; i<n; i++)
if(search==stu[i].getID())
{
ch='a';
cout<<endl; j=0;
if(j==0)
stu[i].tableHeader();
                 cout<<stu[i].getID()<<"\t"<<stu[i].getName()<<"\t"
<<stu[i].getSex()<<"\t"<<stu[i].getAddress()<<"\t"
            <<stu[i].getMat()<<"\t"<<stu[i].getPhy()<<"\t"<<stu[i].getKhmer()
<<"\t"<<stu[i].getTotal()<<"\t"<<stu[i].getAverage()
<<"\t"<<stu[i].getGrade()<<"\t"<<stu[i].getRank()<<endl;
}
            if(ch=='a')
cout<<endl<<"Search sucessful! "<<endl;
else cout<<endl<<"No ID in record! "<<endl;
}
void searchByName(Student stu[], int n){
char name[25], ch;
cout<<endl<<"Search By Name: "; gets(name);
         cout<<endl;stu[0].tableHeader();
for(int i=0; i<n; i++)
if(strcmp(name, stu[i].getName())==0)
{
ch='b';
cout<<stu[i].getID()<<"\t"<<stu[i].getName()<<"\t"
          <<"\t"<<stu[i].getSex()<<"\t"<<stu[i].getAddress()<<"\t"
            <<stu[i].getMat()<<"\t"<<stu[i].getPhy()<<"\t"<<stu[i].getKhmer()
<<"\t"<<stu[i].getTotal()<<"\t"<<stu[i].getAverage()
<<"\t"<<stu[i].getGrade()<<"\t"<<stu[i].getRank()<<endl;
            }
if(ch=='b')
cout<<endl<<"Search sucessful! "<<endl;
else cout<<endl<<"No Name in record! "<<endl;
}
   void searchByRank(Student stu[], int n){
int rank; char ch;
         cout<<endl<<"Search By Rank: "; cin>>rank;
         cout<<endl;stu[0].tableHeader();
for(int i=0; i<n; ++i)
if(rank==stu[i].getRank()){
ch='d';
cout<<stu[i].getID()<<"\t"<<stu[i].getName()<<"\t"
<<stu[i].getSex()<<"\t"<<stu[i].getAddress()<<"\t"<<stu[i].getMat()<<"\t"
  <<stu[i].getPhy()<<"\t"<<stu[i].getKhmer()
  <<"\t"<<stu[i].getTotal()<<"\t"<<stu[i].getAverage()
<<"\t"<<stu[i].getGrade()<<"\t"<<stu[i].getRank()<<endl;
}
if(ch=='d')
cout<<endl<<"Search sucessful! "<<endl;
          else cout<<endl<<"No Rank in record! "<<endl;
}
   void deleteRecord(Student stu[],int d, int n){
d = d - 1;
for(int i=0;i<n;i++){
          if(stu[i].getID()==stu[d].getID())
 for(int j=i;j<n;j++){
stu[j].setData(stu[j+1]);
}
}
cout<<"delete sucessful!";
}
void Update(Student stu[], int n){
int search,a, b;
cout<<"Update ID: "; cin>>search;
        /* if(cin.peek()!=10 || cin.good()!=1)
         {
          cin.clear();
            char ch[100];
            cin.getline(ch,100);

         } */

for(int i=0; i<n; i++)
if(search==stu[i].getID()){
cout<<endl<<"1.Update name"<<endl;
cout<<"2.Update sex"<<endl;
cout<<"3.Update scores"<<endl;
cout<<endl<<"Please select menu:";cin>>a;
cout<<endl<<endl;
                      /* if(cin.peek()!=10 || cin.good()!=1)
                       {
                           cin.clear();
                           char ch[100];
                      cin.getline(ch,100);
                       } */
switch(a){
case 1:
stu[i].insertName(); break;
case 2:
stu[i].insertSex(); break;
case 3:
                            clrscr();
                                 cout<<"Subject to Update:"<<endl;
                                 cout<<"--------------------";
                                 cout<<endl<<"1.Update Math:"<<endl;
cout<<"2.Update Phy:"<<endl;
cout<<"3.Update Khmer:"<<endl;
                                       cout<<"4.Update All"<<endl;
cout<<endl<<"Please select menu:";cin>>b;
cout<<endl<<endl;
                                       /*if(cin.peek()!=10 || cin.good()!=1)
                                       {
                                        cin.clear();
                                          char ch[100];
                                          cin.getline(ch,100);

                                       } */
                                       switch(b){
                                           case 1:

                                                stu[i].insertScore(b,search);
                                                break;
                                           case 2:

                                                   stu[i].insertScore(b,search);
                                                   break;
                                           case 3:

                                                   stu[i].insertScore(b,search);
                                                    break;
                                        case 4:
                                          stu[i].insertScores();
                                        break;
                                           default:
                                            if(b<=0 || b>=5)
                                                {
                                                //goto again;
                                                }
                                       }

                                        break;
default:
                            cout<<"Press Try again!";
}
}
}


void main(){
Student stu[size];
int i, x,w; int n=0; int d;
again: clrscr();
gotoxy(35,2); cout<<"Score System Management";
gotoxy(30,3); cout<<"========================";
gotoxy(35,5); cout<<"1. Insert";
gotoxy(35,6); cout<<"2. Udate";
gotoxy(35,7); cout<<"3. Search";
gotoxy(35,8); cout<<"4. delet";
gotoxy(35,9); cout<<"5. sort";
gotoxy(35,10); cout<<"6. display";
gotoxy(35,11); cout<<"7. Exit"<<endl;
cout<<"Please input number(1-7) of menu: "; cin>>x;
cout<<endl;
      if(cin.peek()!=10 || cin.good()!=1){
           cin.clear();
           char ch[100];
           cin.getline(ch,100);
           goto again;
         }
switch(x){
case 1:
clrscr();
if(n>size){
cout<<"Your memory is full! ";
getch(); goto again;
}
insert(stu,n); cout<<endl;
n=n+1; goto again;
case 2:
if(n<=0){
cout<<"Please insert data first!";
getch(); goto again;
}
Update(stu, n);
getch(); goto again;
case 3:
if(n<=0){
cout<<"Please insert data first!";
getch(); goto again;
}
cout<<endl;
                     menusearch:clrscr();
                     gotoxy(29,1);cout<<"With one do you want to search"<<endl;
                     gotoxy(27,2);cout<<"==================================="<<endl;
gotoxy(30,3);cout<<"1.search by ID"<<endl;
                     gotoxy(30,4);cout<<"2.search by Name"<<endl;
gotoxy(30,5);cout<<"3.search by Rank"<<endl<<endl;
gotoxy(30,6);cout<<"Please select menu: ";cin>>w;
                     if(cin.peek()!=10 || cin.good()!=1){
                        cin.clear();
                        char ch[100];
                        cin.getline(ch,100);
                        goto menusearch;
                  }
          switch(w){
case 1:
searchByID(stu, n);
  getch(); goto again;
case 2:
searchByName(stu, n);
  getch(); goto again;
case 3:
searchByRank(stu, n);
  getch(); goto again;
                default:
                      if(w<=0 || w>=5){
                            goto menusearch;
                           }
}
case 4:
if(n<=0){
  cout<<"Please insert data first!";
getch(); goto again;
                  }else
                  {
                  cout<<"Delete ID: "; cin>>d;
                  if(d>n || d<=0){

getch(); goto again;

}else{
deleteRecord(stu,d,n);
n=n-1;
getch(); goto again;
}
                  }
case 5:
if(n<=0){
cout<<"Please insert data first!";
getch(); goto again;
}cout<<endl;
                  menusort:clrscr();
                     gotoxy(29,1);cout<<"With one do you want to Sort"<<endl;
                     gotoxy(27,2);cout<<"==================================="<<endl;
gotoxy(30,3);cout<<"1.Sort by ID"<<endl;
                     gotoxy(30,4);cout<<"2.Sort by Name"<<endl;
gotoxy(30,5);cout<<"3.Sort by Average"<<endl<<endl;
gotoxy(30,6);cout<<"Please select menu: ";cin>>x;
                     if(cin.peek()!=10 || cin.good()!=1){
                        cin.clear();
                        char ch[100];
                        cin.getline(ch,100);
                        goto menusort;
                  }
switch(x){
case 1:
sortByID(stu, n);
                                 getch(); goto again;
case 2:
sortByName(stu, n);
getch(); goto again;
case 3:
sortByAverage(stu, n);
getch(); goto again;
default:
                      if(x<=0 || x>=4){
                                  goto menusort;
                                 }
                     }
case 6:
if(n<=0){
  cout<<"Please insert data first!"<<endl;
                        getch(); goto again;
                  }else{
                  stu[0].tableHeader();
  for(i=0; i<n; i++){
  rank(stu,n);
  stu[i].display();
  }cout<<"\n\n\tPress any key to continue...";
                  getch();
                  goto again;
                  }
case 7: clrscr();
            gotoxy(35,2); cout<<"Member of Group";
gotoxy(30,3); cout<<"========================";
                  gotoxy(35,5); cout<<"1.VIN SAVRY";
gotoxy(35,7); cout<<"2.PHY SOPEAK";
gotoxy(35,9); cout<<"3.TUN SOMANITA";
                  gotoxy(35,11); cout<<"4.VIN KIAT";
gotoxy(35,13); cout<<"5.CHIM CHANPUN";
                  gotoxy(35,15); cout<<"6.CHUM RITEKAN"<<endl;
                  gotoxy(25,17); cout<<"Press any key to exit program...";
  getch();exit(0);
default:
            if(x<=0 || x>=8)
                  {
                goto again;
                  }
}
}