Get query results using array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deiv82
    New Member
    • Jul 2010
    • 10

    Get query results using array

    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:

    Code:
    while ($results = mysql_fetch_array($query)) {
    	$id = $results['id'];
    	$name = $results['name'];
            ...
    }
    ... something like this

    Code:
    $fields = array("id","name", ...);
    $i = 0;
    	
    while ($results = mysql_fetch_array($query)) {
    	$id = $results[$fields[$i]];
    	$name = $results[$fields[$i]];
    	...
           $i++
    }
    Ok, this doesn't work... but is there maybe some other way...?

    Thanks
    Last edited by PsychoCoder; Jul 20 '12, 02:13 AM. Reason: Code tags
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    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

    Comment

    • ariful alam
      New Member
      • Jan 2011
      • 185

      #3
      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.

      Comment

      • deiv82
        New Member
        • Jul 2010
        • 10

        #4
        ok, sorry for the wrong section... anyway thanks from your answer they might be useful to me!

        Comment

        Working...