Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unable to view more than two rows of data.

    I have added a clause into my program so that it will check to see if the individual that is logged in is an Administrator or a user, if the individual is an user, the program displays only the row of data specific to that user. If the individual logged in is an administrator, then the program should display the entire contents of the table, however, it is displaying only two rows of data and that is it. I have checked my MySQL database and there are several more rows of data sitting on the database.
    If someone can inform me why this is happening it would be much appreciated.
    My code is as follows.

    PHP Code:
    <?php
    session_start
    ();
    if (!isset(
    $_SESSION['user']))
    {
     die (
    "Access Denied");
    }
    ?> 
    <h2>My Account </h2>
    <?php if (isset($_SESSION['user'])) { ?>

    <p>Logged in as <?php echo $_SESSION['user']; ?>
    <br /><br />
    <?php
    /* 
            VIEW.PHP
            Displays all data from 'mergedfantasy' table
    */
    $currentuser $_SESSION['user'];
            
    // connect to the database
            
    include('connect-db.php');

            
    // get results from database
            
    $result mysql_query("SELECT * FROM mergedfantasy WHERE user_email='$currentuser'"
                    or die(
    mysql_error());  

            
    // display data in table
            //echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View By Pages</a></p>";
            
            
    echo "<table border='1' cellpadding='10' align='center'>";
            echo 
    "<tr> <th>ID</th> <th>Full Name</th> <th>Phone Number</th> <th>Email</th> <th>Commission</th> <th>total</th> <th>Comments</th> <th colspan='3' align='center'>Modify Records</th></tr>";
            
            
    // Loop through results of database query, displaying them in the table        
            
    if($currentuser == 'admin@admin.com') {
            
            
    // Display all rows because user is logged in as administrator.
                
    echo 'You are logged in as the Administrator.';
                
                
    // echo out the contents of each row into a table
                
    echo "<tr>";
                echo 
    '<td>' $row['id'] . '</td>';
                echo 
    '<td>' $row['full_name'] . '</td>';
                echo 
    '<td>' $row['phone'] . '</td>';
                echo 
    '<td>' $row['user_email'] . '</td>';
                echo 
    '<td>$' $row['commission'] . '</td>';
                echo 
    '<td>$' $row['total'] . '</td>';
                echo 
    '<td>' $row['comments'] . '</td>';                                
                
    //echo '<td><a href="percent.php?id=' . $row['id'] . '">Percent</a></td>';
                
    echo '<td><a href="edit.php?id=' $row['id'] . '">Edit Account</a></td>';
                echo 
    '<td><a href="delete.php?id=' $row['id'] . '">Delete Account</a></td>';
                echo 
    '<td><a href="settings.php">Change Password</td>';
                echo 
    "</tr>";            
            }
            while(
    $row mysql_fetch_array$result )) {
                    
    // Displays only row pertinent to user logged in(Specified in $currentuser)
                    // echo out the contents of each row into a table
                    
    echo "<tr>";
                    echo 
    '<td>' $row['id'] . '</td>';
                    echo 
    '<td>' $row['full_name'] . '</td>';
                    echo 
    '<td>' $row['phone'] . '</td>';
                    echo 
    '<td>' $row['user_email'] . '</td>';
                    echo 
    '<td>$' $row['commission'] . '</td>';
                    echo 
    '<td>$' $row['total'] . '</td>';
                    echo 
    '<td>' $row['comments'] . '</td>';                                
                    
    //echo '<td><a href="percent.php?id=' . $row['id'] . '">Percent</a></td>';
                    
    echo '<td><a href="edit.php?id=' $row['id'] . '">Edit Account</a></td>';
                    echo 
    '<td><a href="delete.php?id=' $row['id'] . '">Delete Account</a></td>';
                    echo 
    '<td><a href="settings.php">Change Password</td>';
                    echo 
    "</tr>"
            } 

            
    // close table>
            
    echo "</table>";
     
    ?>
     <a href="logout.php">Logout</a>&nbsp; &nbsp; &nbsp; <a href="settings.php">Change Password</a>
     <?php ?>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    I don't see how it even gets two rows.

    Maybe your database is screwed up.

    Given that you use the SAME QUERY for both cases--this one:
    Code:
    mysql_query("SELECT * FROM mergedfantasy WHERE user_email='$currentuser'")
    you should ONLY get ONE row of data. The row for the ONE AND ONLY user_email that matches $currentuser

    Period.

    If you want the administrator to see all rows, then the administrator should be using a *DIFFERENT* query.

    Oh, what the heck. I don't use PHP, but I think I can write this simple code even so.
    Code:
    <?php
    session_start();
    if (!isset($_SESSION['user']))
    {
     die ("Access Denied");
    }
    ?> 
    <h2>My Account </h2>
    <?php if (isset($_SESSION['user'])) { ?>
    
    <p>Logged in as <?php echo $_SESSION['user']; ?>
    <br /><br />
    <?php
    /* 
            VIEW.PHP
            Displays all data from 'mergedfantasy' table
    */
    $currentuser = $_SESSION['user'];
    
    // connect to the database
    include('connect-db.php');
    
    // choose which SQL to use
    if($currentuser == 'admin@admin.com') {
        echo 'You are logged in as the Administrator.<br/>\n';
        $sql = "SELECT * FROM mergedfantasy ORDER BY user_email";
    } else {
        $sql = "SELECT * FROM mergedfantasy WHERE user_email='$currentuser'";
    }
    
    // display data in table
    // don't use PHP to write out blocks of HTML with no PHP contente
    ?>
    <p><b>View All</b> | <a href='view-paginated.php?page=1'>View By Pages</a></p>
    
    <table border='1' cellpadding='10' align='center'>";
    <tr> 
        <th>ID</th> 
        <th>Full Name</th> 
        <th>Phone Number</th> 
        <th>Email</th> 
        <th>Commission</th> 
        <th>total</th> 
        <th>Comments</th> 
        <th colspan='3' align='center'>Modify Records</th>
    </tr>
    <?
    // Loop through results of database query, displaying them in the table
    // for all users except admin, there will ONLY be one row in the result
    // for admin, all users will be in the result
    //
    $result = mysql_query( $sql ) or die(mysql_error());  
    
    while($row = mysql_fetch_array( $result )) {
        // echo out the contents of each row into a table
        echo "<tr>";
        echo '<td>' . $row['id'] . '</td>';
        echo '<td>' . $row['full_name'] . '</td>';
        echo '<td>' . $row['phone'] . '</td>';
        echo '<td>' . $row['user_email'] . '</td>';
        echo '<td>$' . $row['commission'] . '</td>';
        echo '<td>$' . $row['total'] . '</td>';
        echo '<td>' . $row['comments'] . '</td>';        
        //echo '<td><a href="percent.php?id=' . $row['id'] . '">Percent</a></td>';
        echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit Account</a></td>';
        echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete Account</a></td>';
        echo '<td><a href="settings.php">Change Password</td>';
        echo "</tr>"; 
    } 
    ?>
    </table>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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