Jump to content

Recommended Posts

Hello i am new to programming and i am trying to create an if statement for a tinyint i have in my database, but don't know where to place it. Basically i want to say when $userType equals 0 "NO" and when $userType equals 1 "YES" this is to present in a table

 

<?php
require_once('auth.php');
?>

<?php
//Start session
session_start();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View Users</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />

<style type="text/css">
    body {
font: 11px Verdana, Arial, Helvetica, sans-serif;
color: #666666;
margin: 0px;
padding: 20px 10px 0px;
}

/* general style */
.list{
    margin:0;
    padding:0;
        width:840px;
}
.list li{

    list-style: none;
    margin:2px 0;
    overflow:hidden;
    border-bottom:1px solid #eee;
}
.entries span, .heading span{
    display:block;
    width:155px; /* (~width of list) / 5 keep in mind the boxmodel*/
    float:left;
    padding-left:12px;
    border-right:1px solid #eee;
    line-height: 30px;
    height:30px;
}
.heading span{
    background: #CAE8EA;
}
/* entries */
</style>
</head>
<body>

<h1>View Users</h1>
<a href="member-profile.php">Orders</a> | <a href="users.php">Users</a> | <a href="logout.php">Logout</a>
<?php
//Include database connection details
require_once('config.php');

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");	





$sql = mysql_query("SELECT * FROM newUsers2 ORDER BY member_id ASC");

$id = 'member_id';
$fname = 'firstname';
$lname = 'lastname';
$login = 'login';
$userType = 'userType';




echo '<ul class="list">' ; 
echo  '<li class="heading">';
echo '<span class="id">ID </span>' ;
echo '<span class="firstname">FIRST NAME </span>' ;
echo '<span class="lastname">LAST NAME </span>' ;
echo '<span class="login">LOGIN </span>' ;
echo '<span class="userType">ADMIN RIGHTS</span>';  
echo '</li>' ;  

while ($rows = mysql_fetch_assoc($sql)){

echo '<li class="entries">' ;
echo '<span class="id">' .$rows[$id]. '</span>' ;
echo '<span class="firstname">' .$rows[$fname]. '</span>' ;
echo '<span class="lastname">' .$rows[$lname]. '</span>' ;
echo '<span class= "login">' .$rows[$login]. '</span>';
echo  '<span class="userType">' .$rows[$userType]. if ($userType == 0) { echo "NO"; } elseif ($userType == 1) { echo "YES"};'</span>' ;
echo '</li>' ;
}	  
echo '</ul>' ;  
?>    
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/240912-if-statement-help/
Share on other sites

Try this.

 

<?php
require_once('auth.php');
?>

<?php
//Start session
session_start();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View Users</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />

<style type="text/css">
    body {
font: 11px Verdana, Arial, Helvetica, sans-serif;
color: #666666;
margin: 0px;
padding: 20px 10px 0px;
}

/* general style */
.list{
    margin:0;
    padding:0;
        width:840px;
}
.list li{

    list-style: none;
    margin:2px 0;
    overflow:hidden;
    border-bottom:1px solid #eee;
}
.entries span, .heading span{
    display:block;
    width:155px; /* (~width of list) / 5 keep in mind the boxmodel*/
    float:left;
    padding-left:12px;
    border-right:1px solid #eee;
    line-height: 30px;
    height:30px;
}
.heading span{
    background: #CAE8EA;
}
/* entries */
</style>
</head>
<body>

<h1>View Users</h1>
<a href="member-profile.php">Orders</a> | <a href="users.php">Users</a> | <a href="logout.php">Logout</a>
<?php
//Include database connection details
require_once('config.php');

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");	





$sql = mysql_query("SELECT * FROM newUsers2 ORDER BY member_id ASC");

$id = 'member_id';
$fname = 'firstname';
$lname = 'lastname';
$login = 'login';
$userType = 'userType';

echo '<ul class="list">' ; 
echo  '<li class="heading">';
echo '<span class="id">ID </span>' ;
echo '<span class="firstname">FIRST NAME </span>' ;
echo '<span class="lastname">LAST NAME </span>' ;
echo '<span class="login">LOGIN </span>' ;
echo '<span class="userType">ADMIN RIGHTS</span>';  
echo '</li>' ;  

while ($rows = mysql_fetch_assoc($sql)){

if($rows[$userType] == 1) {
$userTypeValue = "YES";
} else {
$userTypeValue = "NO";
}

echo '<li class="entries">' ;
echo '<span class="id">' .$rows[$id]. '</span>' ;
echo '<span class="firstname">' .$rows[$fname]. '</span>' ;
echo '<span class="lastname">' .$rows[$lname]. '</span>' ;
echo '<span class= "login">' .$rows[$login]. '</span>';
echo  '<span class="userType">' .$userTypeValue. '</span>' ;
echo '</li>' ;
}	  
echo '</ul>' ;  
?>    
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/240912-if-statement-help/#findComment-1237505
Share on other sites

<?php



require_once('auth.php');
?>

<?php
//Start session



session_start();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View Users</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />

<style type="text/css">
    body {



font: 11px Verdana, Arial, Helvetica, sans-serif;



color: #666666;



margin: 0px;



padding: 20px 10px 0px;
}

/* general style */
.list{
    margin:0;
    padding:0;
        width:840px;
}
.list li{

    list-style: none;
    margin:2px 0;
    overflow:hidden;
    border-bottom:1px solid #eee;
}
.entries span, .heading span{
    display:block;
    width:155px; /* (~width of list) / 5 keep in mind the boxmodel*/
    float:left;
    padding-left:12px;
    border-right:1px solid #eee;
    line-height: 30px;
    height:30px;
}
.heading span{
    background: #CAE8EA;
}
/* entries */
</style>
</head>
<body>

<h1>View Users</h1>
<a href="member-profile.php">Orders</a> | <a href="users.php">Users</a> | <a href="logout.php">Logout</a>
<?php
//Include database connection details



require_once('config.php');

//Connect to mysql server



$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);



if(!$link) {





die('Failed to connect to server: ' . mysql_error());



}

//Select database



$db = mysql_select_db(DB_DATABASE);



if(!$db) {





die("Unable to select database");









$sql = mysql_query("SELECT * FROM newUsers2 ORDER BY member_id ASC");

$id = 'member_id';
$fname = 'firstname';
$lname = 'lastname';
$login = 'login';


echo '<ul class="list">' ; 
echo  '<li class="heading">';
echo '<span class="id">ID </span>' ;
echo '<span class="firstname">FIRST NAME </span>' ;
echo '<span class="lastname">LAST NAME </span>' ;
echo '<span class="login">LOGIN </span>' ;
echo '<span class="userType">ADMIN RIGHTS</span>';  
echo '</li>' ;  

while ($rows = mysql_fetch_assoc($sql)){

if($rows['userType'] == 1) {
$userTypeValue = "YES";
} else {
$userTypeValue = "NO";
}

echo '<li class="entries">' ;
echo '<span class="id">' .$rows[$id]. '</span>' ;
echo '<span class="firstname">' .$rows[$fname]. '</span>' ;
echo '<span class="lastname">' .$rows[$lname]. '</span>' ;
echo '<span class= "login">' .$rows[$login]. '</span>';
echo  '<span class="userType">' .$userTypeValue. '</span>' ;
echo '</li>' ;
}



  
echo '</ul>' ;  
?>    
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/240912-if-statement-help/#findComment-1237518
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.