abrahamgarcia27 Posted July 2, 2011 Share Posted July 2, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/240912-if-statement-help/ Share on other sites More sharing options...
QuickOldCar Posted July 2, 2011 Share Posted July 2, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/240912-if-statement-help/#findComment-1237505 Share on other sites More sharing options...
abrahamgarcia27 Posted July 2, 2011 Author Share Posted July 2, 2011 I tried it and I been moving that code around can't make it seem to work any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/240912-if-statement-help/#findComment-1237509 Share on other sites More sharing options...
QuickOldCar Posted July 2, 2011 Share Posted July 2, 2011 Does $rows[$userType] have a value if echo it anywhere in your while loop? Is it exactly userType in your database? Quote Link to comment https://forums.phpfreaks.com/topic/240912-if-statement-help/#findComment-1237513 Share on other sites More sharing options...
abrahamgarcia27 Posted July 2, 2011 Author Share Posted July 2, 2011 the field in the table of my database is userType if echo just userType this is what i get [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/240912-if-statement-help/#findComment-1237514 Share on other sites More sharing options...
QuickOldCar Posted July 2, 2011 Share Posted July 2, 2011 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/240912-if-statement-help/#findComment-1237518 Share on other sites More sharing options...
abrahamgarcia27 Posted July 2, 2011 Author Share Posted July 2, 2011 Thanks that worked Quote Link to comment https://forums.phpfreaks.com/topic/240912-if-statement-help/#findComment-1237523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.