473,385 Members | 2,044 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,385 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 3011
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...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.