www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to display User Specific content from Table in PHP

  1. #1
    Join Date
    Feb 2014
    Posts
    1

    Lightbulb How to display User Specific content from Table in PHP

    I have 8 rows/columns. They are;
    Key (which will never repeat), Name, HireDate, Seniority, VacHrs, PTOhrs, username AND password.

    After a successful login, this is my code;

    PHP Code:
    <?php
    $dbhost 
    '***7.**********.com';
    $dbuser 'a3674631_***';
    $dbpass 'm***';
    $conn mysql_connect("mysql17.**********.com""a36***31_***n9""****08");
    if(! 
    $conn )
    {
      die(
    'Could not connect: ' mysql_error());
    }
    $sql 'SELECT Name, HireDate, Seniority, VacHrs, PTOhrs FROM att';

    mysql_select_db('a3674631_test');
    $retval mysql_query$sql$conn );
    if(! 
    $retval )
    {
      die(
    'Could not get data: ' mysql_error());
    }
    while(
    $row mysql_fetch_array($retvalMYSQL_NUM))
    {
        echo 
    "Name :{$row[0]}  <br> ".
             
    "Hire Date : {$row[1]} <br> ".
             
    "Seniority : {$row[2]} <br> ".
             
    "Vacation Hours Remaining : {$row[3]} <br> ".
             
    "PTO Hours Remaining : {$row[4]} <br> ".
             
    "--------------------------------<br>";
    }
    mysql_free_result($retval);
    echo 
    "Fetched data successfully\n";
    mysql_close($conn);
    ?>
    The problem I’m having is it’s putting everyone’s data, all on one page together for everyone to see. This is private information, and Person A should not be able to see the values for person B. My table has 6 records(currently). If user A has a login of 111791, on a successful login, I would like it to say;

    Name: First Last
    HireDate: 04/04/2012
    Seniority: 1 (dates that are sorted by earliest to latest)
    VacHrs: 45
    PTOhrs: 18
    Key, username & password will never show.

    Can someone tell me what I’m doing wrong. I know that I’m a noob, so please skip all the “I need read this book….or that tutorial”. I know I do, I’m going to, but in the mean time, I need to get this taken care of. I thank you sincerely for any help.
    Last edited by NogDog; 02-05-2014 at 10:32 AM. Reason: Got rid of bold-red formatting of text

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,326
    Please don't yell at us in bold red text. There is a reason books are still printed in black type on white(ish) paper, even though they could use red ink if they wanted to. (And nobody is going to be more inclined to help you because it's in red.)

    Now I'm off to edit your post so that I can actually read it.

    QFT:
    Quote Originally Posted by demon917 View Post
    I have 8 rows/columns. They are;
    Key (which will never repeat), Name, HireDate, Seniority, VacHrs, PTOhrs, username AND password.

    After a successful login, this is my code;


    PHP Code:
    <?php
    $dbhost 
    '***7.**********.com';
    $dbuser 'a3674631_***';
    $dbpass 'm***';
    $conn mysql_connect("mysql17.**********.com""a36***31_***n9""****08");
    if(! 
    $conn )
    {
      die(
    'Could not connect: ' mysql_error());
    }
    $sql 'SELECT Name, HireDate, Seniority, VacHrs, PTOhrs FROM att';

    mysql_select_db('a3674631_test');
    $retval mysql_query$sql$conn );
    if(! 
    $retval )
    {
      die(
    'Could not get data: ' mysql_error());
    }
    while(
    $row mysql_fetch_array($retvalMYSQL_NUM))
    {
        echo 
    "Name :{$row[0]}  <br> ".
             
    "Hire Date : {$row[1]} <br> ".
             
    "Seniority : {$row[2]} <br> ".
             
    "Vacation Hours Remaining : {$row[3]} <br> ".
             
    "PTO Hours Remaining : {$row[4]} <br> ".
             
    "--------------------------------<br>";
    }
    mysql_free_result($retval);
    echo 
    "Fetched data successfully\n";
    mysql_close($conn);
    ?>
    The problem I’m having is it’s putting everyone’s data, all on one page together for everyone to see. This is private information, and Person A should not be able to see the values for person B. My table has 6 records(currently). If user A has a login of 111791, on a successful login, I would like it to say;

    Name: First Last
    HireDate: 04/04/2012
    Seniority: 1 (dates that are sorted by earliest to latest)
    VacHrs: 45
    PTOhrs: 18
    Key, username & password will never show.

    Can someone tell me what I’m doing wrong. I know that I’m a noob, so please skip all the “I need read this book….or that tutorial”. I know I do, I’m going to, but in the mean time, I need to get this taken care of. I thank you sincerely for any help.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,326
    Sounds like you want to add some sort of WHERE clause to your DB query to only select rows with specific user, probably based on `username`, perhaps from your $_SESSION data?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles