Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/200848-problem-selecting-data-and-comparing-it/
Share on other sites

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.

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.

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>

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.