Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Mar 20, 2006, 07:20   #1
wackyflik
SitePoint Zealot
 
Join Date: Jun 2005
Posts: 123
States' names do not appear in the dropdown list.

i created a class named ECISState in a single file named ecisstate.php. then i include the file in the common.php where all classes' files are included here. i have called 1 of the function in the ECISState in common.php. then, i failed to load all the states' names in the dropdown list in the employer_block.php. did i called the loadState function wrongly?

ecisstate.php

PHP Code:

<?php

class ECISState
{
    function
ECISState()
    {
        
//nothing
    
}
    
    function
loadState()
    {
        
$state[0] = "Johor";
        
$state[1] = "Kelantan";
        
$state[2] = "Kuala Lumpur";
        
$state[3] = "Labuan";
        
$state[4] = "Melaka";
        
$state[5] = "Negeri Sembilan";
        
$state[6] = "Pahang";
        
$state[7] = "Perak";
        
$state[8] = "Perlis";
        
$state[9] = "Pulau Pinang";
        
$state[10] = "Sabah";
        
$state[11] = "Sarawak";
        
$state[12] = "Selangor";
        
$state[13] = "Terengganu";
        
$countState = count($state);
    }
}
?>
common.php

PHP Code:

/*******************

* State Handler
*******************/
$ecisState = new ECISState;
$state = $ecisState->loadState();
employer_block.php

PHP Code:

<select name="emp_state" id="emp_state">

      <option selected>Select</option>
      <?php for($i = 0; $i < $countState; $i++) { ?>
      <option value="<?php echo $state[$i]; ?>"><?php echo $state[$i]; ?></option>
      <?php } ?>
      </select>
wackyflik is offline   Reply With Quote
Old Mar 20, 2006, 08:10   #2
Jelena
SitePoint Wizard
silver trophy
 
Jelena's Avatar
 
Join Date: Feb 2005
Location: Universum, 3rd Corner
Posts: 3,760
You function should return $state array.
PHP Code:

<?php

class ECISState
{
    function
ECISState()
    {
        
//nothing
    
}
    
    function
loadState()
    {
        
$state[0] = "Johor";
        
$state[1] = "Kelantan";
        
$state[2] = "Kuala Lumpur";
        
$state[3] = "Labuan";
        
$state[4] = "Melaka";
        
$state[5] = "Negeri Sembilan";
        
$state[6] = "Pahang";
        
$state[7] = "Perak";
        
$state[8] = "Perlis";
        
$state[9] = "Pulau Pinang";
        
$state[10] = "Sabah";
        
$state[11] = "Sarawak";
        
$state[12] = "Selangor";
        
$state[13] = "Terengganu";
        
        return
$state;
    }
}

$ecisState = new ECISState;
$state = $ecisState->loadState();

?>

<select name="emp_state" id="emp_state">
      <option selected>Select</option>
      <?php for($i = 0; $i < count($state); $i++) { ?>
      <option value="<?php echo $state[$i]; ?>"><?php echo $state[$i]; ?></option>
      <?php } ?>
</select>
Jelena is offline   Reply With Quote
Old Mar 20, 2006, 09:07   #3
wackyflik
SitePoint Zealot
 
Join Date: Jun 2005
Posts: 123
i have tried your code jelena, but it only works if i put everything in a single file. the structure of system is like this. employer_block.php is in the different folder.

ecis
----
|_folder: include ->common.php, ecisstate.php, etc.
|_folder: templates ->employer_block.php, etc.
|_file: index.php, etc.


all classes will be included in common.php

PHP Code:

include_once ("../ecis_cfg.php");

include_once (
"mysql.php");
include_once (
"ecismembership.php");
include_once (
"ecisemployer.php");
include_once (
"ecisstate.php");
include_once (
"ecissupplier.php");
global
$ecisDB, $ecisMember, $ecisEmployer, $ecisState;

/*******************
* State Handler
*******************/
$ecisState = new ECISState;
$state = $ecisState->loadState();
wackyflik is offline   Reply With Quote
Old Mar 20, 2006, 09:11   #4
Jelena
SitePoint Wizard
silver trophy
 
Jelena's Avatar
 
Join Date: Feb 2005
Location: Universum, 3rd Corner
Posts: 3,760
Well, you have to include common.php in template files or in files which include template files.
Jelena is offline   Reply With Quote
Old Mar 20, 2006, 09:12   #5
F4nat1c
Wadge!
 
F4nat1c's Avatar
 
Join Date: Oct 2005
Location: South Wales, UK
Posts: 1,148
Make $state a global variable too.

PHP Code:

global $ecisDB, $ecisMember, $ecisEmployer, $ecisState, $state; 

F4nat1c is offline   Reply With Quote
Old Mar 20, 2006, 09:34   #6
wackyflik
SitePoint Zealot
 
Join Date: Jun 2005
Posts: 123
sorry, i am confusing actually. for example, in common.php, i have initiated

PHP Code:

$ecisMember = new ECISMembership;

$user = $ecisMember->getUserInfo($_SESSION['u_id']);
then, i just declare global $ecisMember at any files, for example at process/user_registration.php which is in different folder with include/common.php. then i just use the $ecisMember and i can call any functions from class ECISMembership. i dont need to include any files in user_registration.php.

but anyway, thanks guys. i will fix it the rest.
wackyflik is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 18:19.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved