?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?Natural order sorting - natsort
Author:??(---.neptune.ca)
Date:???03-24-03 09:47

Greetings,

Does anyone know how to properly use natsort on result from a query? I have searched hi and low and can only find a reference to it in the php manual. What I'm trying to figure out is how to natural sort a table from a mysql query. Here is some code I'm working with:

require($DOCUMENT_ROOT . "/siteplans/inc/siteplans_db.inc");

$table_name=$phasenumber;
$lot_sql="SELECT lot_number FROM $table_name WHERE availability LIKE 'For Sale' OR availability LIKE 'Re-listed' ORDER BY lot_number ASC LIMIT 0,17";

$result=mysql_db_query($data_base, $lot_sql, $conn);
$array_lot_number = array();
while ($row = mysql_fetch_array($result)) {
$array_temp = array($row[0]);
$array_lot_number = array_merge($array_lot_number, $array_temp);
}

// sorting on natural algorithm
$array_lot_number = natsort($array_lot_number);

// set pointer to first entry
reset ($array_lot_number);

while (list ($key, $val) = each ($array_lot_number)) {

?>

echo $key;
echo $val;
}
?>

Here are the two errors I'm getting:
1) Variable passed to reset() is not an array or object
2) Variable passed to each() is not an array or object

Does anyone know a better way of doing this? or know what I'm doing wrong?

thanks

?Topics Author? Date
?Natural order sorting - natsort??new
Kirk 03-24-03 09:47?
Go to Top??|??Go to Topic??|??Flat View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??wrote: > > Greetings, > > Does anyone know how to properly use natsort on result from a > query? I have searched hi and low and can only find a > reference to it in the php manual. What I'm trying to figure > out is how to natural sort a table from a mysql query. Here > is some code I'm working with: > > require($DOCUMENT_ROOT . "/siteplans/inc/siteplans_db.inc"); > > $table_name=$phasenumber; > $lot_sql="SELECT lot_number FROM $table_name WHERE > availability LIKE 'For Sale' OR availability LIKE 'Re-listed' > ORDER BY lot_number ASC LIMIT 0,17"; > > $result=mysql_db_query($data_base, $lot_sql, $conn); > $array_lot_number = array(); > while ($row = mysql_fetch_array($result)) { > $array_temp = array($row[0]); > $array_lot_number = array_merge($array_lot_number, > $array_temp); > } > > // sorting on natural algorithm > $array_lot_number = natsort($array_lot_number); > > // set pointer to first entry > reset ($array_lot_number); > > while (list ($key, $val) = each ($array_lot_number)) { > > ?> > > echo $key; > echo $val; > } > ?> > > Here are the two errors I'm getting: > 1) Variable passed to reset() is not an array or object > 2) Variable passed to each() is not an array or object > > Does anyone know a better way of doing this? or know what I'm > doing wrong? > > thanks ">??

Provided By
Phorum