Jump to content

doing define wrong


TheSky

Recommended Posts

im doing it wrong can some one help me ? , thanks

{

define('userlevel'( 9="admin" , 1="guest"));

}

It helps if you tell use what you're trying to do with it.

 

The function define is used to create constants. Constants are like variables expect you cannot change their values once you have created them. I don't think this is the function you want to use.

 

I think what you're trying to do is associate a users userlevel with a title, eg  when a user has a userlevel of 9 give them the title of admin. If it is 1 give them a title of guest.

 

Link to comment
https://forums.phpfreaks.com/topic/236118-doing-define-wrong/#findComment-1213906
Share on other sites

<?php
include("xxxx.php");
$sql=mysql_query("SELECT * FROM users ORDER BY userid DESC LIMIT 0,5") or die(mysql_error());
$x=0;
while($row=mysql_fetch_array($sql))
{
($x+1).'. '.$row['username'].'.  kasutaja tüüp  '.$row['userlevel'].'<br />';
//let's add some define values
define('userlevel');

if(defined('1')) {
  echo Külaline . '<br />';
}

if(defined('9')) {
  echo Administraator . '<br />';
}
$x++;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/236118-doing-define-wrong/#findComment-1213917
Share on other sites

You'll want to use a switch statement. Not define.

switch($row['userlevel'])
{
    case 1:
        echo 'Külaline';
    break;
    
    case 9:
        echo 'Administraator';
    break;
}

When $row['userlevel'] is 1 it'll echo Külaline.

When $row['userlevel'] is 9 it'll echo Administraator.

Link to comment
https://forums.phpfreaks.com/topic/236118-doing-define-wrong/#findComment-1213938
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.