473,226 Members | 1,660 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,226 software developers and data experts.

Sorting results of odbc_exec???

Hi

I am running a PHP program that connects to an Access 2000 database
via ODBC:
$results = odbc_exec($connection_id, $sql_select);

Is it possible to sort the contents of $results? I wish to use a
regex-based sort order that you can't do in Access 2000* SQL with
"ORDER BY".

Thanks!

Karin

* There is the function rgxValidate by John Nurick, which uses
VBScript.Regexp to provide a regex fn for Access, but this is slow
in queries because it creates a RegExp object and compiles the
regular expression every time it is called.

Aug 26 '05 #1
7 2996
Karin Jensen wrote:
Hi

I am running a PHP program that connects to an Access 2000 database
via ODBC:
$results = odbc_exec($connection_id, $sql_select);

Is it possible to sort the contents of $results? I wish to use a
regex-based sort order that you can't do in Access 2000* SQL with
"ORDER BY".

Thanks!

Karin

* There is the function rgxValidate by John Nurick, which uses
VBScript.Regexp to provide a regex fn for Access, but this is slow
in queries because it creates a RegExp object and compiles the
regular expression every time it is called.


Hi,

PHP is so friendly, you can write your own comparision-functions, which you
can let PHP call to define how to sort.
:-)

Have a look at usort
http://nl2.php.net/usort

See also uasort(), uksort().

Good luck!

Regards,
Erwin Moller
Aug 26 '05 #2
*** Karin Jensen wrote/escribió (Fri, 26 Aug 2005 10:40:03 +0100):
Is it possible to sort the contents of $results? I wish to use a
regex-based sort order that you can't do in Access 2000* SQL with
"ORDER BY".


I haven't checked the manual but I guess odbc_*() functions do now allow
custom sorting. However, there're array functions that allow such task. So
you'd need to load all results into an array. I hope the query doesn't
return 10,000 records ;-)

uasort()
uksort()
usort()

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Aug 26 '05 #3
Erwin Moller wrote:
Karin Jensen wrote:
Hi
I am running a PHP program that connects to an Access 2000
database via ODBC:
$results = odbc_exec($connection_id, $sql_select);
Is it possible to sort the contents of $results? I wish to use a
regex-based sort order that you can't do in Access 2000* SQL
with "ORDER BY".


Hi,

PHP is so friendly, you can write your own comparision-functions,
which you can let PHP call to define how to sort.
:-)

Have a look at usort
http://nl2.php.net/usort

See also uasort(), uksort().


Thanks, Erwin! Sorry to ask more, but the question I was getting at
was whether (in my example) $results would have to be dealt with in
a special way, as it is from an ODBC function.

I am new to PHP and not sure what sort of object $results is or how
to find out what sort of object it is.

PHP clearly knows that $results is ODBC-derived, as you have to
extract data/info from it using special functions (odbc_fetch_row,
odbc_result and so on). I was wondering if this affected how you
would sort it.

Many thanks,

Karin
Aug 26 '05 #4
On Fri, 26 Aug 2005, Alvaro G Vicario wrote:
I haven't checked the manual but I guess odbc_*() functions do now
allow custom sorting. However, there're array functions that allow
such task. So you'd need to load all results into an array. I hope
the query doesn't return 10,000 records ;-)


Thanks, Alvaro. Excuse my ignorance, but what would be the syntax
for loading the results into an array? I'm not clear how to deal
with odbc results outside the odbc function set.

Best wishes,

Karin

Aug 26 '05 #5
Karin Jensen wrote:
Erwin Moller wrote:
Karin Jensen wrote:
Hi
I am running a PHP program that connects to an Access 2000
database via ODBC:
$results = odbc_exec($connection_id, $sql_select);
Is it possible to sort the contents of $results? I wish to use a
regex-based sort order that you can't do in Access 2000* SQL
with "ORDER BY".
Hi,

PHP is so friendly, you can write your own comparision-functions,
which you can let PHP call to define how to sort.
:-)

Have a look at usort
http://nl2.php.net/usort

See also uasort(), uksort().


Thanks, Erwin! Sorry to ask more, but the question I was getting at
was whether (in my example) $results would have to be dealt with in
a special way, as it is from an ODBC function.

I am new to PHP and not sure what sort of object $results is or how
to find out what sort of object it is.


Hi,

Yes, your $result is a special case: it is a 'resource'.
I wouldn't be surprised if you could treat it like an array after some
fiddling around, but I do not know.
Safest bet is to copy all the rows to your own array-structure, then use
that structure to do the sorting.

But a fair warning, if you have little experience with PHP and arrays in
PHP, you better take a day or two to get some experience.
PHP is very powerfull when it comes to arrays, but things can get
confusing/intimidating in the beginning.

eg: Try to create your own datastructures, using strings as keys.

$myArr["userid12"]["name"] = "john";
$myArr["userid12"]["city"] = "Amsterdam";
$myArr["userid12"]["admin"] = "N";
$myArr["userid12"]["articles"][] = 21;
$myArr["userid12"]["articles"][] = 26;

$myArr["userid23"]["name"] = "Bert";
$myArr["userid23"]["city"] = "Los Angeles";
$myArr["userid23"]["admin"] = "Y";
$myArr["userid23"]["articles"][] = 17;

etc.

PHP can use the keys ("useridxx") as material to do the sorting AND keep the
underlying arrays coupled to the keys.

I (and others) find that kind of datarepresentation extremely powerfull to
use and easy to implement.
(Note: My example is a bit over the top, but illustrates the use of
associative arrays to create/store all kind of datastructures.)

Well, just read up at php.net about arrays, it is all there. :-)

Good luck.

Regards,
Erwin Moller

PHP clearly knows that $results is ODBC-derived, as you have to
extract data/info from it using special functions (odbc_fetch_row,
odbc_result and so on). I was wondering if this affected how you
would sort it.

Many thanks,

Karin


Aug 26 '05 #6
Karin Jensen wrote:
On Fri, 26 Aug 2005, Alvaro G Vicario wrote:
I haven't checked the manual but I guess odbc_*() functions do now
allow custom sorting. However, there're array functions that allow
such task. So you'd need to load all results into an array. I hope
the query doesn't return 10,000 records ;-)


Thanks, Alvaro. Excuse my ignorance, but what would be the syntax
for loading the results into an array? I'm not clear how to deal
with odbc results outside the odbc function set.

Best wishes,

Karin


Hi Karin,

These kind of questions are barely suitable for a ng, not because we don't
want to help you, but because this is all nicely described on www.php.net
including massive examples.

Just go to php.net and start reading about arrays, for-next, while, and
databasequeries.
Really, it is all there including examples.

Good luck.

Regards,
Erwin Moller
Aug 29 '05 #7
Erwin Moller wrote:
Karin Jensen wrote:
On Fri, 26 Aug 2005, Alvaro G Vicario wrote:
I haven't checked the manual but I guess odbc_*() functions do
now allow custom sorting. However, there're array functions
that allow such task. So you'd need to load all results into an
array. I hope the query doesn't return 10,000 records ;-)


Thanks, Alvaro. Excuse my ignorance, but what would be the
syntax for loading the results into an array? I'm not clear how
to deal with odbc results outside the odbc function set.


These kind of questions are barely suitable for a ng, not because
we don't want to help you, but because this is all nicely
described on www.php.net including massive examples.

Just go to php.net and start reading about arrays, for-next,
while, and databasequeries.
Really, it is all there including examples.


Sorry, I think it is partly my fault for not being clear. I have no
problem in using or sorting arrays. My initial question was about
sorting an ODBC resource.

In the follow up question above, I was wondering if there was a
quick way of putting ODBC results into array. From the ODBC
reference pages, the command "odbc_fetch_into" fetches one result
row into an array. Is there a single-line way of getting the ODBC
results into a multi-dimensional array without looping through the
rows? (Note, I am not asking how to do the latter, just whether it
is necessary!)

Thanks for your patience,

Karin

Aug 30 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Poe | last post by:
Hi, Consider the following: <? $username = "foo"; $password = "bar"; $host = "db";
0
by: mk | last post by:
Hi to all, I want to execte some query using odbc_exec, but i receive the following error both using odbc_exec or odbc_prepare. Connection is successful but the other functions will fail. PHP...
7
by: Brett Romero | last post by:
I have a dataset with one table, which has four columns. All are of type INT. I need to convert this dataset into a dataview so I can sort on the last three columns. I may sort one of the three...
0
by: u4yk | last post by:
I posted this on php.dev, but I'd give you guys a shot. I'm running PHP 5.1.1 on a Linux box, and when I try to send an MS SQL database via ODBC, I get the following error: PHP Warning: ...
1
by: stonicus | last post by:
// Relevant parts of my DB class (from include file) class db_connection { function __construct() { $this->con = odbc_connect('ShippingData','name','pass'); } private...
2
by: JoeNinja | last post by:
Im failing to update the an MS ACcess. I will appreciate Your advice. I get the error below Warning: odbc_exec() : SQL error: Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
1
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging in the database versus to creating a CLR sort...
0
by: CislaghiAndrea | last post by:
Pc configuration : XAMPP per Windows Version 1.5.1 PHP Version 5.1.1 IBM DB2 ODBC DRIVER 8.01.14 the query ==> Database DB2 IBM 8.1 on Z9 with ZOS 1.9 odbc_exec($db,"SELECT * FROM...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.