Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:42:45+00:00 2026-06-13T08:42:45+00:00

I have the following code which gets a users data from a table based

  • 0

I have the following code which gets a users data from a table based on their log in details

//==========================================
//  CONNECT TO THE LOCAL DATABASE
//==========================================
$user_name = "xxxx";
$pass_word = "xxxxx";
$database = "xxxx";
$server = "xxxxxx";

$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {
    $SQL = "SELECT * FROM students WHERE L1 = '$uname' AND L2 = '" .md5 ($_POST['password'])."'";
    $result = mysql_query($SQL);
    $num_rows = mysql_num_rows($result);

    //====================================================
    //  CHECK TO SEE IF THE $result VARIABLE IS TRUE
    //====================================================

    if ($result) {
        if ($num_rows > 0) {
            $color="1";

            $result = mysql_query("SELECT * FROM entry, students   WHERE entry.studentName = students.studentName AND students.L1='$uname' ") or die(mysql_error());  

            echo "<p>Welcome "; echo $row[studentName];
            echo "<p>You records as of ";
            echo date('l jS \of F Y h:i:s A');  

            echo "<table border='1' cellpadding='2' cellspacing='0'>";
            echo "<tr> <th>Date</th><th>Student Name</th> <th>Tutor name</th> <th>Procedure name</th> <th>Grade</th><th>Student Reflection</th><th>Tutor Comments</th><th>Professionalism</th> <th>Communication</th> <th>Alert</th> <th>Dispute</th> </tr>";
            // keeps getting the next row until there are no more to get

            while($row = mysql_fetch_array( $result )) {
                if($color==1){
                    echo "<tr bgcolor=#DDD ><td>".$row['date']."</td><td>".$row['studentName']."</td><td>".$row['tutorName']."</td><td>".$row['procedureName']."</td><td>".$row['grade']."</td><td>".$row['studentReflection']."</td><td>".$row['tutorComments']."</td><td>".$row['professionalism']."</td><td>".$row['communication']."</td><td>".$row['alert']."</td><td>".$row['dispute']."</td></tr>";

                    // Set $color==2, for switching to other color
                    $color="2";
                }
                // When $color not equal 1, use this table row color
                else {
                    echo "<tr bgcolor='#CCC'><td>".$row['date']."</td><td>".$row['studentName']."</td><td>".$row['tutorName']."</td><td>".$row['procedureName']."</td><td>".$row['grade']."</td><td>".$row['studentReflection']."</td><td>".$row['tutorComments']."</td><td>".$row['professionalism']."</td><td>".$row['communication']."</td><td>".$row['alert']."</td><td>".$row['dispute']."</td></tr>";
                    // Set $color back to 1
                    $color="1";
                }
            }
            echo '</table>';
        }

What I want to do it is echo or print out the users name above the table but I am having difficulty doing so. The only want I can get it it to work is to add it to the while loop but then it prints it out as many times as the user has records.

Can you help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:42:46+00:00Added an answer on June 13, 2026 at 8:42 am

    You will need to fetch the first row in order to gain access to the user information. That means you will have to call mysql_fetch_array once before the loop.

    That will get you in trouble, because you will also need to call it in the loop. You could hack around that by using all kinds of boolean flags or copies of the row, but the best way is to change the structure of your code a little.

    Use a do-while loop, combined with an if statement. This allows you to fetch a single row first, and take special action if none is found. After that, you got a loop that does what it does now, only it checks if there is a next row after the iteration instead of before, otherwise the first row would be skipped in the table output.

    if ($row = mysql_fetch_array( $result )) {
      // Print user info
      // Print table header
    
      do {
    
        // Print table row
    
      } while ($row = mysql_fetch_array( $result ));
    
      // Print table footer
    }
    else
    {
      // User not found. Print error or whatever.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which definitely returns a proper data result if I
I have the following code, which is a modified version from MSDN's website, to
I have the following JavaScript code which gets all of the id's of the
I have the following code to fetch the data from URL, store it in
I have the following code which gets the user's current zipcode and displays it
I have following code which works for radio buttons but need to be changed
I want to know is below code correct ? I have following code which
I have the following code which is working, I was wondering if this can
I have the following code which is used to upload large files (~6MB) to
i have the following code which switches some fullscreen-background-images (fadeOut, fadeIn). setInterval(function() { var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.