MYSQL Fields with brackets in them?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nerdstyle
Forum Newbie
Posts: 1
Joined: Thu Aug 11, 2005 9:20 pm

MYSQL Fields with brackets in them?

Post by Nerdstyle »

Hey I was working on a PHP script and I wanted to have some of my mysql fields names be in the form of an array but it won't work with mysql_fetch_object is there a way to do this? Or is there a better way of doing what I am trying to do?

Code: Select all

// the name of my field is "buyamount[0]"

$result = mysql_query("SELECT * FROM u_store WHERE uid = '$uid'") or die('Query failed. ' . mysql_error()); 
$store = mysql_fetch_object( $result );

echo "$store->buyamount[0]";
I don't get anything as output.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

$result = mysql_query("SELECT * FROM u_store WHERE uid = '$uid'") or die('Query failed. ' . mysql_error()); 
$array = mysql_fetch_assoc($result);
$array is an array of associative values for the result. To return the indexes uses mysql_fetch_row(). To return indexes and associative values use mysql_fetch_array().
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply