Dark57 Posted May 5, 2010 Share Posted May 5, 2010 I'm not sure how I was describe my problem other than a lack of knowledge on my own part. I have tried a few ways but this is the only way I can get it to work. Now the problem with the code I have is that I believe it is checking the entire database to see if one person has "Shinobi" status, and if one person has it then it gives it to everyone. if ($row['shinobi'] > 0) { echo "<strong>" . "[" . $_SESSION['id']. "] " . $_SESSION['username'] . "</strong>"; } My problem is that I guess I don't understand how I'm supposed to get it to just select the person whose logged in Shinobi status using their ID number. In the code above you can see my problem. How would I go about doing this? <?php session_start(); if(!isset($_SESSION['username'])) { header("location:main_login.php"); } ?> <table width="800" border="0" align="center"> <tr> <td colspan="2" bgcolor="#402E16"> </td> </tr> <tr> <td width="200" bgcolor="#402E16"><img src="images/Header-redo3.jpg" width="200" height="100" alt="Header" /></td> <td width="590" bgcolor="#402E16"><?php $con = mysql_connect("127.0.0.1","xxxx","xxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("SNO1", $con); $result = mysql_query("SELECT * FROM Basic"); $row = mysql_fetch_array($result); if ($row['shinobi'] > 0) { echo "<strong>" . "[" . $_SESSION['id']. "] " . $_SESSION['username'] . "</strong>"; } else { echo "[".$_SESSION['id']."] ".$_SESSION['username']; } ?></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/ Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 before I re-code this, what is your obgective here? is this a login script that shows a different output for those that are "Shinobi" or is it simply to identify if an already authenticated user is a "Shinobi"? Quote Link to comment https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/#findComment-1053872 Share on other sites More sharing options...
Dark57 Posted May 5, 2010 Author Share Posted May 5, 2010 If the user has Shinobi status their name will appear bolded, if they do not have Shinobi status their name will be normal. That's all that section of the script is trying to do, since I couldn't even get it to do that I didn't even attempt to make it do all the rest of the things that differ from Shinobi and Non-Shinobi. Quote Link to comment https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/#findComment-1053874 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 So you have the login and authentication already done some place else? Quote Link to comment https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/#findComment-1053876 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 what values are stored in the "Basic.shinobi" column in the database? Quote Link to comment https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/#findComment-1053879 Share on other sites More sharing options...
Dark57 Posted May 5, 2010 Author Share Posted May 5, 2010 An integer, for User ID #1 it has 1000 in it, for user #2 it has 0 in it. The integer stands for how many days the user has left in Shinobi status. And yes, login and authentication is done elsewhere. That works fine, the session transfers over properly but I don't know how to select information specifically from just one column from a specific row. Quote Link to comment https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/#findComment-1053883 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 ok, try this : <?php session_start(); if(!isset($_SESSION['username'])) { header("location:main_login.php"); } ?> <table width="800" border="0" align="center"> <tr> <td colspan="2" bgcolor="#402E16"> </td> </tr> <tr> <td width="200" bgcolor="#402E16"><img src="images/Header-redo3.jpg" width="200" height="100" alt="Header" /></td> <td width="590" bgcolor="#402E16"><?php $con = mysql_connect("127.0.0.1","xxxx","xxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("SNO1", $con); $result = mysql_query("SELECT shinobi FROM Basic WHERE id = ".$_SESSION['id']) or die (mysql_error()); $row = mysql_fetch_assoc($result); if ($row['shinobi'] > 0) { echo "<strong>Congratulations ".$_SESSION['username'].". You still have ".$row['shinobi']." days left as Shinobi</strong>"; } else { echo "[".$_SESSION['id']."] ".$_SESSION['username']; } ?></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/#findComment-1053888 Share on other sites More sharing options...
Dark57 Posted May 5, 2010 Author Share Posted May 5, 2010 It does work, thank you for helping me. I actually had the jest of what I had to do, but I was putting it in the wrong spot. It does help to have an active community to help you figure out what you're doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/#findComment-1053889 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.