Hi, everyone i have some problem getting the user account type from db i create a row on db called acc_type, it checks if user acc_type is 1 or greater highlight the user name. i wrote this code but it highlights all the username as red (admin) colors meaning: Blue = Regular member = 0 Red = admin = 1 Green = Mod = 2 Orange = Super User = 3 <?php $req = mysql_query('select acc_type from users where id="'.$id.'"');while($dn3 = mysql_fetch_array($req)){?><?php if(isset($dn3) && $dn3['acc_type'] == 1) { ?> <style> .acc{ color:red; font-weight:bold; } </style> <?php } ?> <?php if(isset($dn3) && $dn3['acc_type'] == 2) { ?> <style> .acc{ color:green; font-weight:bold; } </style> <?php } ?> <?php if(isset($dn3) && $dn3['acc_type'] == 3) { ?> <style> .acc{ color:#FFA500; font-weight:bold; } </style> <?php } ?> <?}?> <tr> <td class="forum_tops"><a href="read_topic.php?id=<?php echo $dnn2['id']; ?>"><?php echo htmlentities($dnn2['title'], ENT_QUOTES, 'UTF-8'); ?></a></td> <td><a href="profile.php?id=<?php echo $dnn2['authorid']; ?>"><span style="" class="acc"><?php echo htmlentities($dnn2['author'], ENT_QUOTES, 'UTF-8'); ?></span></a></td> <td><?php echo $dnn2['replies']; ?></td> PHP: Thanks
I hope you mean a field (column), not a record (row). You can't name records. Ignoring the fact that $dnn2 never gets any data (I assume that was done before any of this code): while($dn3 = mysql_fetch_array($req)){ if(isset($dn3)) PHP: is redundant. If $dn3 isn't set, it's not "while $dn3", so you wouldn't be there.
didn't work however the page have while $dnn2 before while $dn3 , means its have 2 while. <?php while($dnn2 = mysql_fetch_array($dn2)) { ?> this works on users profile : <?php $req = mysql_query('select acc_type from users Where id="'.$id.'"'); while($dnn2 = mysql_fetch_array($req)) { ?>
ok now im getting the users account number, exp 0 = member , 1 = admin, 2 = mod, but the if statement is not working: if (isset($req) && $req['acc_type'] == 0) {echo "<style> .acc{ color:blue; font-weight:bold; } </style>"; } elseif (isset($req) && $req['acc_type'] == 1){echo "<style> .acc{ color:red; font-weight:bold; } </style>"; } elseif (isset($req) && $req['acc_type'] == 2){ echo "<style> .acc{ color:green; font-weight:bold; } </style>"; } ?> PHP: or view the code here http://pastebin.com/CuXPAkqu .
the data type is Int img http://oi46.tinypic.com/avpmyv.jpg as you can seen in the code if $acc_type = 1 then its admin 0 is regular member 1 is admin 2 is mod
Try this: error_reporting(32767); echo '"'.$req.'"'; if (isset($req) && $req['acc_type'] == 0) { Code (markup): What do you get? It should be "0" or "1" or some number in quotes. And do you get any error? (If $req isn't set you'll get a fatal error.)
it should be 0 means regular user, and i changed acc_type number to 1 in db 1 means admin, and for another user its acc_type 2 = mod. see img: http://oi48.tinypic.com/fvwznn.jpg
Try putting the numbers in single quotes. It defaults to red because it is validating as TRUE and not the number 1. Perhaps the db column is not numeric. if($dn3['acc_type'] == '1') { not if($dn3['acc_type'] == 1) {
it changes all username color to green code: if($dn2['acc_type']== '1'){ echo '<style>.acc{color:red;font-weight:bold;}</style>'; } else{ echo '<style>.acc{color:green;font-weight:bold;}</style>'; } ?> <span class="acc"><?php echo $dnn2['author']; ?></span> im thinking there is something wrong in selecting from db/row $req = mysql_query('select acc_type from users where id="'.$id.'"'); PHP: .. .
Never mind guys i fixed, there was nothing wrong with the php code, it was the css problem. but thanks for trying to help