By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,601 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

Get query results using array

P: 10
Hi everybody,

just would like to ask to someone more expert than me if it's possible to use a variable (or maybe better, array) as name of the column from which I should get the results with the query.

So I mean instead of this:

Expand|Select|Wrap|Line Numbers
  1. while ($results = mysql_fetch_array($query)) {
  2.     $id = $results['id'];
  3.     $name = $results['name'];
  4.         ...
  5. }
... something like this

Expand|Select|Wrap|Line Numbers
  1. $fields = array("id","name", ...);
  2. $i = 0;
  3.  
  4. while ($results = mysql_fetch_array($query)) {
  5.     $id = $results[$fields[$i]];
  6.     $name = $results[$fields[$i]];
  7.     ...
  8.        $i++
  9. }
  10.  
Ok, this doesn't work... but is there maybe some other way...?

Thanks
Jul 17 '12 #1
Share this Question
Share on Google+
3 Replies


ck9663
Expert 2.5K+
P: 2,878
I think it's more of a question for your front-end tool and not sql server. You might be able to access the resultset using an object that uses a number based property to identify the sequence of columns in a resultset.

Good Luck!!!


~~ CK
Jul 17 '12 #2

ariful alam
100+
P: 185
if you are required to pike single column then you may use single dimensional array or for row columns, you may need to use a double dimensional array.

And by the way, this is a question of front-end that you used to pike query result.
Jul 17 '12 #3

P: 10
ok, sorry for the wrong section... anyway thanks from your answer they might be useful to me!
Jul 17 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.