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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:28:45+00:00 2026-05-27T14:28:45+00:00

Possible Duplicate: one variable row inside another variable row I have script something like

  • 0

Possible Duplicate:
one variable row inside another variable row

I have script something like –

$sql = "SELECT * FROM `users`"
$q = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($q);
$sql1 = "SELECT * FROM `other_table`";
$q1 = mysql_query($sql1) or die(mysql_error());
$row1 = mysql_fetch_array($q1);
$item = $row1[$row['username']];

How can I set one variable row inside another, since it don’t work. Basically, I need to select username, and then select column with user username from other table, in which is written user points.

I was thinking about adding –

$sql = "SELECT * FROM `users`"
$q = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($q);
$sql1 = "SELECT `".$row['username']."` FROM `other_table` WHERE `uid` = 1";
$q1 = mysql_query($sql1) or die(mysql_error());
$row1 = mysql_fetch_array($q1);
$item = $row1[xxxxxxxxxx]; // DONT KNOW HOW TO DEFINE IT, so it takes out found variable (there is only one).

I have question already, but not with full info, and I don’t know how to delete it :(!

Here is my table –

Users

‘id’–‘name’
‘1’–‘Bil’
‘2’–‘Conor’
‘3’–‘Ilian’

Other_table (which holds points for users)

‘id’–‘Bil’–‘Conor’–‘Ilian’
‘1’–‘2’–‘3′–’55’

Don’t ask, why I don’t hold the points in the same table, since if I could, I would do that ;)!

  • 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-27T14:28:46+00:00Added an answer on May 27, 2026 at 2:28 pm

    It sounds like you need to redesign the tables to start with, I would suggest a table structure like this:

    Table Users
    ID | Name
    
    Table Points
    UserID | Points
    

    This way you can add a foreign key constraint between the tables and then do a simple join query like:

    SELECT U.Name, P.Points FROM Users AS U INNER JOIN Points AS P ON U.ID = P.UserID
    

    Then your php code would look like:

    $sql = "SELECT U.Name, P.Points FROM Users AS U INNER JOIN Points AS P ON U.ID = P.UserID";
    $q = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_array($q);
    

    Here are the create table queries for you:

    CREATE TABLE Users (ID INT NOT NULL AUTO_INCREMENT,
        Name VARCHAR(50) NOT NULL, PRIMARY KEY (ID))
    CREATE TABLE Points (UserID INT NOT NULL, Points INT,
        FOREIGN KEY(UserID) REFERENCES Users(ID) ON UPDATE CASCADE ON DELETE CASCADE)
    

    EDIT:

    This should allow you to get the value (NOTE: untested as I don’t have a php/mysql instance to mess with currently), but for a more robust solution you really should look into redesigning your table schema.

    $userName = $row['username'];
    $sql1 = "SELECT [". $userName ."] FROM other_table WHERE [uid] = 1";
    $q1 = mysql_query($sql1) or die(mysql_error());
    $row1 = mysql_fetch_array($q1);
    $item = $row1[$userName];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: SQL - find records from one table which don't exist in another
Possible Duplicate: Referencing control on one form from another form VB.NET This is the
Possible Duplicate: How many Python classes should I put in one file? Coming from
Possible Duplicate: SQL Server: Can I Comma Delimit Multiple Rows Into One Column? I
Possible Duplicate: Child Scope & CS0136 C# Variable Scoping Though I have been using
Possible Duplicate: C++ passing variables in from one Function to the Next. The Program
Possible Duplicate: Why does one often see null != variable instead of variable !=
Possible Duplicate: Why does one often see “null != variable” instead of “variable !=
Possible Duplicate: Should I initialize variable within constructor or outside constructor I have here
Possible Duplicate: How to extract a file extension in PHP? I have a variable

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.