Jump to content


Accessing MYSQL Fields In a Loop


1 reply to this topic

#1 Nerdstyle

    Young Padawan

  • Members
  • Pip
  • 29 posts

Posted 16 March 2006 - 04:09 PM

Hey I am trying to access each of my fields in my database using a for loop...

The data base has 6 fields that I am trying to get. newprice0 newprice1 all the way up to newprice5

This is the code I was trying to use but it won't group the number with the field.
		//MARKET CALCULATION
		$result = mysql_query("SELECT * FROM g_market LIMIT 1") or die("Please Contact Admin:  " . mysql_error());
		$market = mysql_fetch_object($result);

			for ($i = 0; $i <= 5; $i++)
			{
				echo  "$market->$newprice{$i}";
			}


It displays 0 1 2 3 4 5

it should display the value of each field in the database.

Anyone have any ideas?

#2 Nerdstyle

    Young Padawan

  • Members
  • Pip
  • 29 posts

Posted 16 March 2006 - 05:51 PM

So I figured it out. I used this for accessing them.

$market->{"newprice".$i}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users