473,378 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Get query results using array

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
3 3025
ck9663
2,878 Expert 2GB
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
185 100+
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
deiv82
10
ok, sorry for the wrong section... anyway thanks from your answer they might be useful to me!
Jul 17 '12 #4

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

Similar topics

1
by: Guy Erez | last post by:
Hi, I'm running queries with MySql 4.0.17 that return thousands of records. Because I need to present them in GUI, I returieve the results in chunks using LIMIT, for example - get first 100,...
2
by: Terri | last post by:
I know formatting should be handled in the client app and not in SQL Server but this is the situation I must develop in so any help would be appreciated. I'm running the following in Query...
3
by: William Wisnieski | last post by:
Hello Everyone, Access 2000, I have a main unbound form with a bound datasheet subform . The subform is bound to a query that returns records based on criteria in the main form. The user...
0
by: Rob | last post by:
I doubt this is the best way to do it, but what I came up with was to hide the XML in an HTML Comment then edit the file deleting the HTML stuff and keep the XML results. If anyone has a better...
7
by: fcolon75 | last post by:
I'm an experienced Access user, but very new to coding VBA in Access. I'd like to do the following: 1) Develop a basic query in the query designer. 2) Call that query from a VBA script 3)...
3
by: neelesh kumar | last post by:
sir, in my database i have a query which is taking the subjectcodes for a particular testid. suppose if for particular testid it takes ma,phy,che , i want to insert the query results in array in...
3
shane3341436
by: shane3341436 | last post by:
I need to unite two or more sql query results into one single array of results. The two tables have unequal number of columns. I tried to do this by for an example: $sql="SELECT P_id id,P_fname...
1
by: igor221189 | last post by:
Hello everyone. I have Access 2000 database which holds student records in the school.It stores subject grades for each student.In the 'Student Grade Form', I would like to search student surname...
1
by: mcfly1204 | last post by:
I am generating an XML document using C#, and I have a question on how to populate the value of a particular object with the corresponding value from a SQL query. For example, if I have a query...
1
by: Dave Mallett | last post by:
very new to Access. Trying to export query results via macro and transfertext, but keep getting error message stating "Microsoft Jet Engine cannot find the object 'HRQ-DM_Prd1_qtr.txt'. Make sure...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.