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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:42:34+00:00 2026-06-03T17:42:34+00:00

I seem to have looked everywhere for this. Here is the code i use

  • 0

I seem to have looked everywhere for this.

Here is the code i use to set a variable to a piece of data from a MySQL database

$PartNo=mysql_result($result,$i,"PartNo");

Where

 $result = mysql_query("SELECT * FROM PriceList"); 

$i = 0, is added to by 1 every time my while loop restarts
PartNo is a field name in my MySQL table and also the name of the variable I want to set the data in the database to
PriceList is my database name

I want to loop through all the field names (the array has them) and set variables with the same names to that data. Like this:

$PartNo=mysql_result($result,$i,"PartNo");
$Group=mysql_result($result,$i,"Group");
$OnHand=mysql_result($result,$i,"OnHand");
$QOO=mysql_result($result,$i,"QOO");
$Description=mysql_result($result,$i,"Desc");
$Cost=mysql_result($result,$i,"Cost");

But with a foreach loop so it isn’t as much code.
I was thinking something like this, but it won’t execute no matter which way I go about it (parse_str, eval, exec, etc.)

$nDatabaseVars=array("PartNo","Group","OnHand","QOO","Desc","Cost");

foreach ($nDatabaseVars as $X) {
    $$X=mysql_result($result,$i,'$X');
}

I need “$$X” to evaluate out so on the first iteration, it changes to $PartNo= and then sets $PartNo to whatever data is in the database on the first line. Which is what this part is: mysql_result($result,$i,"PartNo")

If I echo it out instead:

foreach ($nDatabaseVars as $X) {
    echo "$$X=mysql_result($result,$i,'$X')";
}

I can get it to say exactly what I need executed ($PartNo=mysql_result($result,$i,”PartNo”);) but not actually get the variable set.

  • 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-03T17:42:35+00:00Added an answer on June 3, 2026 at 5:42 pm

    You are passing a string containing "$X" to mysql_result, not the name of your column. Remove the single quotes:

    $$X=mysql_result($result, $i, $X);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok.. I have looked through this site and just can't seem to find the
I seem to have an issue with connecting to an embedded FireBird database from
I have looked high and low and can't seem to find this anywhere. Does
I've looked everywhere, but can't seem to find a solution to this problem. I'm
I have looked through the answers in this forum but cannot seem to find
I have looked at other questions and answers regarding this, but can't seem to
I have looked at this for hours and can't seem to figure out what
I have looked pretty much everywhere but cannot seem to find an awnser to
I looked everywhere but none of the suggestions on here seem to work for
I have looked in the official documentation for python, but i cannot seem to

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.