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 6766297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:48:46+00:00 2026-05-26T14:48:46+00:00

Bit confused with this one. Basically, I have a column in a table, and

  • 0

Bit confused with this one.

Basically, I have a column in a table, and I want to retrieve the value in that column, for a specific row.

I have one set of code that works, but not in this particular situation.

The code I have that works is this:

$qry="SELECT * FROM logins WHERE username='$login' AND password='$password'";
$result=mysql_query($qry);

This obviously retrieves that particular row, and then:

$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['User ID'];

This successfully sets the session variable, as the value from the user id column from this row.

So that’s fine, that works. The code I am trying to use in my new situation is this:

$qry = "SELECT * FROM vote WHERE Username = '" .$_SESSION['SESS_USERNAME']. "'";
$result = mysql_query($qry);

This gets the row based on the current user, and then:

 while($row = mysql_fetch_array( $result )) 
 { 
 Print "<b>Name:</b> ".$row['Username'] . " <br>"; 
 Print "<b>Vote:</b> ".$row['Vote'] . " "; 
 } 

The while loop works correctly, it displays the current username, and their vote. Obviously I felt the loop was not required as I already have just the one row selected. Removing the loop broke it, so I put it back. Not a big deal, I can live with that if it gets the job done.

The issue I am focusing on, is the use of the

$row['Username']

In this if statement:

 if($row['Username'] == "Admin") {
 echo ("Win!<br />");
 }
 else {
 echo "Failed!";
 }

When printing from the loop above, it prints:

 Name, as Admin, 
and vote, as 0. 

If I then try to validate using the if statement, I ask it to echo Win! if the username == Admin.

Obviously it is true as it has printed it on the line before, however, it always prins Fail! and I can’t understand why.

Should I set $row[‘Username’] as some other variable?

Can anyone offer their guidance please?

Cheers

Eds

  • 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-05-26T14:48:47+00:00Added an answer on May 26, 2026 at 2:48 pm

    The problem stems from your loop:

    while($row = mysql_fetch_array( $result )) 
     { 
     Print "<b>Name:</b> ".$row['Username'] . " <br>"; 
     Print "<b>Vote:</b> ".$row['Vote'] . " "; 
     } 
    

    The first time through, $row is set to the row of data from the database. It then tries to go through the loop again, but since there is only one row, mysql_fetch_array returns false. now $row is set to false. So any code after the loop won’t have access to the data anymore.

    The solution would be to replace your loop with a simple if statement:

     if ($row = mysql_fetch_array( $result )) 
     { 
       Print "<b>Name:</b> ".$row['Username'] . " <br>"; 
       Print "<b>Vote:</b> ".$row['Vote'] . " "; 
     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused on this. I have a data table structured like this:
I am a bit confused with this: I have a page with a set
Bit confused with this one so bear with me... I have a Navigation-based project
I'm a bit confused as to why this isn't working; I assume that because
I'm a bit confused on how to approach this problem. I have a large
I am a bit confused: We have a chat application that has a requirement
I am a bit confused why this code compiles. I leave out the necessary
I am a bit confused about this. If you're building a distributed application, which
This is a bit confused question for those who don't now advanced SQL... However.
I am getting myself a bit confused about how to go about this. My

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.