ORDER BY is not sorting
am 31.07.2007 21:42:44 von Mark Abrams
Sorry, this seams very trivial but I can not sort the result set for any
field. What am I doing wrong?
php & mySQL 5
....
$table_name ='users';
// Select records
$result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
// Loop through the record set
while($row = mysql_fetch_array($result)) {
print 'rowID =' .$row['rowID']. '
'
}
?>
1
2
3
4
TIA
Mark
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ORDER BY is not sorting
am 31.07.2007 21:59:57 von Dan Shirah
------=_Part_8047_10494124.1185911997327
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Well, it looks like you're trying to get your results in an array and run
the query all at the same time. Also, I believe you need to put the variable
in your SELECT statement inside of some single quotes.
Try something like this:
$query = "SELECT * FROM '$table_name' ORDER BY DESC";
$result = mysql_query($sql) or die(mysql_error());
Then you can take your $result variable and output the data, put it into a
loop, or select specific records.
Hope that helps.
On 7/31/07, Mark Abrams wrote:
>
> Sorry, this seams very trivial but I can not sort the result set for any
> field. What am I doing wrong?
>
>
> php & mySQL 5
>
>
>
>
> ...
>
> $table_name ='users';
>
> // Select records
> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
>
>
> // Loop through the record set
> while($row = mysql_fetch_array($result)) {
> print 'rowID =' .$row['rowID']. '
'
> }
>
> ?>
>
> 1
> 2
> 3
> 4
>
>
> TIA
> Mark
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
------=_Part_8047_10494124.1185911997327--
Re: ORDER BY is not sorting
am 31.07.2007 22:32:15 von Trevor Gryffyn
I can't really see anything wrong with what you have there. It shouldn't matter that your SQL is inside the query function, although I like to build the query in a variable outside the query function, but either way it should work.
And you're obviously getting data and not an error, right?
What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1? or still 1, 2, 3, 4?
You might try displaying more data from the result set to see if there's some other issue.
And have you tested the SQL statement just using MySQL via command line, phpMyAdmin, WinSQL, Navicat, or something like that?
-TG
= = = Original message = = =
Sorry, this seams very trivial but I can not sort the result set for any
field. What am I doing wrong?
php & mySQL 5
....
$table_name ='users';
// Select records
$result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
// Loop through the record set
while($row = mysql_fetch_array($result))
print 'rowID =' .$row['rowID']. '
'
?>
1
2
3
4
TIA
Mark
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ORDER BY is not sorting
am 31.07.2007 23:18:55 von Trevor Gryffyn
Spaces would affect sorting if the spaces appeared in the actual rowID data. If rowID is stored as text of some kind, then yeah, maybe he'd have an issue. But I have a feeling you're talking about the code itself and whether to put the quer into a variable or not (rebuting what I said).
Here's his code:
> $table_name ='users';
> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
Code looks fine. $table_name gets substituted for it's value, 'users'. There are no extra spaces in the variable data. Even if there was, that's fine. If it were something like this, he'd have a problem:
> $result = mysql_query("SELECT * FROM ` $table_name` ORDER BY rowID DESC");
Then it would look for a table named users. Which probably doesn't exist.
Also.. that doesn't relate to the sorting issue since sorting is on 'rowID' within that table, which isn't defined in a variable, but stated explicitly in the query.
So not sure what you're saying about spaces messing things up.
-TG
= = = Original message = = =
Well, if you have blank spaces on the field's beginning it won't sort
correctly, it will put the blank spaces on the last results on that case.
On 7/31/07, tg-php@gryffyndevelopment.com
wrote:
>
> I can't really see anything wrong with what you have there. It shouldn't
> matter that your SQL is inside the query function, although I like to build
> the query in a variable outside the query function, but either way it should
> work.
>
> And you're obviously getting data and not an error, right?
>
> What happens if you leave the "DESC" off? Does it come back 4, 3, 2,
> 1? or still 1, 2, 3, 4?
>
> You might try displaying more data from the result set to see if there's
> some other issue.
>
> And have you tested the SQL statement just using MySQL via command line,
> phpMyAdmin, WinSQL, Navicat, or something like that?
>
> -TG
>
> = = = Original message = = =
>
> Sorry, this seams very trivial but I can not sort the result set for any
> field. What am I doing wrong?
>
>
> php & mySQL 5
>
>
>
>
> ...
>
> $table_name ='users';
>
> // Select records
> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID
> DESC");
>
>
> // Loop through the record set
> while($row = mysql_fetch_array($result))
> print 'rowID =' .$row['rowID']. '
'
>
>
> ?>
>
> 1
> 2
> 3
> 4
>
>
> TIA
> Mark
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> ___________________________________________________________
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Bruno Policarpo
brunopolicarpo@gmail.com
MSN brunopolicarpo@hotmail.com
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ORDER BY is not sorting
am 01.08.2007 00:49:56 von Mark Abrams
Is mysql_fetch_array the proper function to access sorted data? The
problem is consistent on my test server and my ISPs mySQL DB.
rowID is the primary key. Do I need to have an index attribute on a field I
want to sort?
wrote in message
news:20070731203155.CEE1819504F@spaceymail-a3.g.dreamhost.co m...
>I can't really see anything wrong with what you have there. It shouldn't
>matter that your SQL is inside the query function, although I like to build
>the query in a variable outside the query function, but either way it
>should work.
>
> And you're obviously getting data and not an error, right?
>
> What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1?
> or still 1, 2, 3, 4?
>
> You might try displaying more data from the result set to see if there's
> some other issue.
>
> And have you tested the SQL statement just using MySQL via command line,
> phpMyAdmin, WinSQL, Navicat, or something like that?
>
> -TG
>
> = = = Original message = = =
>
> Sorry, this seams very trivial but I can not sort the result set for any
> field. What am I doing wrong?
>
>
> php & mySQL 5
>
>
>
>
> ...
>
> $table_name ='users';
>
> // Select records
> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
>
>
> // Loop through the record set
> while($row = mysql_fetch_array($result))
> print 'rowID =' .$row['rowID']. '
'
>
>
> ?>
>
> 1
> 2
> 3
> 4
>
>
> TIA
> Mark
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> ___________________________________________________________
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: ORDER BY is not sorting
am 01.08.2007 08:06:00 von Gustav Wiberg
Hi!
I can't see anything with your code either. Mysql_fetch_array should work f=
ine yes. No indexes are needed to sort fields, but are recommended for spee=
ding up the process :-)
How does the table users look like? (Please send a link to a screenshot or =
something like that)
Sometimes I have noticed that PHP isn't that good of getting right results =
when using $variable inside ""-chars
You could try doing this:
$table_name =3D'users';
// Select records
$result =3D mysql_query("SELECT * FROM " . $table_name . " ORDER BY row=
ID DESC");
// Loop through the record set
while($row =3D mysql_fetch_array($result))
print 'rowID =3D' .$row['rowID']. '
'
There might be some issues regarding permissons of MySQL. Have you tried do=
ing another sql-select statement on another table?
Best regards
/Gustav Wiberg
=20
-----Original Message-----
From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]=20
Sent: Wednesday, August 01, 2007 12:50 AM
To: php-windows@lists.php.net
Subject: Re: [PHP-WIN] ORDER BY is not sorting
Is mysql_fetch_array the proper function to access sorted data? The=20
problem is consistent on my test server and my ISPs mySQL DB.
rowID is the primary key. Do I need to have an index attribute on a field =
I=20
want to sort?
wrote in message=20
news:20070731203155.CEE1819504F@spaceymail-a3.g.dreamhost.co m...
>I can't really see anything wrong with what you have there. It shouldn't=
=20
>matter that your SQL is inside the query function, although I like to buil=
d=20
>the query in a variable outside the query function, but either way it=20
>should work.
>
> And you're obviously getting data and not an error, right?
>
> What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1?=
=20
> or still 1, 2, 3, 4?
>
> You might try displaying more data from the result set to see if there's=
=20
> some other issue.
>
> And have you tested the SQL statement just using MySQL via command line,=
=20
> phpMyAdmin, WinSQL, Navicat, or something like that?
>
> -TG
>
> =3D =3D =3D Original message =3D =3D =3D
>
> Sorry, this seams very trivial but I can not sort the result set for any
> field. What am I doing wrong?
>
>
> php & mySQL 5
>
>
>
>
> ...
>
> $table_name =3D'users';
>
> // Select records
> $result =3D mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC=
");
>
>
> // Loop through the record set
> while($row =3D mysql_fetch_array($result))
> print 'rowID =3D' .$row['rowID']. '
'
>
>
> ?>
>
> 1
> 2
> 3
> 4
>
>
> TIA
> Mark
>
> --=20
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> ___________________________________________________________
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.=20
--=20
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
No virus found in this outgoing message.
Checked by AVG Free Edition.=20
Version: 7.5.476 / Virus Database: 269.11.0/927 - Release Date: 2007-07-30 =
17:02
=20
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ORDER BY is not sorting
am 01.08.2007 11:19:05 von Aleksandar Vojnovic
What kind of field is the keyID? is it int, char, varchar?
- Aleksander
Mark Abrams wrote:
> Is mysql_fetch_array the proper function to access sorted data? The
> problem is consistent on my test server and my ISPs mySQL DB.
>
> rowID is the primary key. Do I need to have an index attribute on a field I
> want to sort?
>
>
>
>
> wrote in message
> news:20070731203155.CEE1819504F@spaceymail-a3.g.dreamhost.co m...
>
>> I can't really see anything wrong with what you have there. It shouldn't
>> matter that your SQL is inside the query function, although I like to build
>> the query in a variable outside the query function, but either way it
>> should work.
>>
>> And you're obviously getting data and not an error, right?
>>
>> What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1?
>> or still 1, 2, 3, 4?
>>
>> You might try displaying more data from the result set to see if there's
>> some other issue.
>>
>> And have you tested the SQL statement just using MySQL via command line,
>> phpMyAdmin, WinSQL, Navicat, or something like that?
>>
>> -TG
>>
>> = = = Original message = = =
>>
>> Sorry, this seams very trivial but I can not sort the result set for any
>> field. What am I doing wrong?
>>
>>
>> php & mySQL 5
>>
>>
>>
>>
>> ...
>>
>> $table_name ='users';
>>
>> // Select records
>> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
>>
>>
>> // Loop through the record set
>> while($row = mysql_fetch_array($result))
>> print 'rowID =' .$row['rowID']. '
'
>>
>>
>> ?>
>>
>> 1
>> 2
>> 3
>> 4
>>
>>
>> TIA
>> Mark
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> ___________________________________________________________
>> Sent by ePrompter, the premier email notification software.
>> Free download at http://www.ePrompter.com.
>>
>
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ORDER BY is not sorting
am 01.08.2007 12:23:56 von Tularis
Gustav Wiberg wrote:
> Hi!
>
> I can't see anything with your code either. Mysql_fetch_array should work fine yes. No indexes are needed to sort fields, but are recommended for speeding up the process :-)
>
> How does the table users look like? (Please send a link to a screenshot or something like that)
>
> Sometimes I have noticed that PHP isn't that good of getting right results when using $variable inside ""-chars
what do you mean by that??? You mean PHP is having trouble getting
'right results' from a mysql database if _somewhere_ in the code there's
an interpolated string? Sounds a bit iffy to me...
- Tul
>
>
> You could try doing this:
>
> $table_name ='users';
>
> // Select records
> $result = mysql_query("SELECT * FROM " . $table_name . " ORDER BY rowID DESC");
>
>
> // Loop through the record set
> while($row = mysql_fetch_array($result))
> print 'rowID =' .$row['rowID']. '
'
>
>
> There might be some issues regarding permissons of MySQL. Have you tried doing another sql-select statement on another table?
>
> Best regards
> /Gustav Wiberg
>
>
>
>
> -----Original Message-----
> From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
> Sent: Wednesday, August 01, 2007 12:50 AM
> To: php-windows@lists.php.net
> Subject: Re: [PHP-WIN] ORDER BY is not sorting
>
> Is mysql_fetch_array the proper function to access sorted data? The
> problem is consistent on my test server and my ISPs mySQL DB.
>
> rowID is the primary key. Do I need to have an index attribute on a field I
> want to sort?
>
>
>
>
> wrote in message
> news:20070731203155.CEE1819504F@spaceymail-a3.g.dreamhost.co m...
>> I can't really see anything wrong with what you have there. It shouldn't
>> matter that your SQL is inside the query function, although I like to build
>> the query in a variable outside the query function, but either way it
>> should work.
>>
>> And you're obviously getting data and not an error, right?
>>
>> What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1?
>> or still 1, 2, 3, 4?
>>
>> You might try displaying more data from the result set to see if there's
>> some other issue.
>>
>> And have you tested the SQL statement just using MySQL via command line,
>> phpMyAdmin, WinSQL, Navicat, or something like that?
>>
>> -TG
>>
>> = = = Original message = = =
>>
>> Sorry, this seams very trivial but I can not sort the result set for any
>> field. What am I doing wrong?
>>
>>
>> php & mySQL 5
>>
>>
>>
>>
>> ...
>>
>> $table_name ='users';
>>
>> // Select records
>> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
>>
>>
>> // Loop through the record set
>> while($row = mysql_fetch_array($result))
>> print 'rowID =' .$row['rowID']. '
'
>>
>>
>> ?>
>>
>> 1
>> 2
>> 3
>> 4
>>
>>
>> TIA
>> Mark
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> ___________________________________________________________
>> Sent by ePrompter, the premier email notification software.
>> Free download at http://www.ePrompter.com.
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: ORDER BY is not sorting
am 01.08.2007 12:35:25 von luis.moreira
Just one thought :
The code itself, as shown, looks good, but is PHP getting what WE see ?
Meaning, try to
1) set a string with the SQL query you want
2) check the string before applying it
Maybe, just maybe, you are getting a broken string, and the "order" part is
missing, thus not being applied...
Luis
-----Original Message-----
From: M. Sokolewicz [mailto:tularis@php.net]
Sent: quarta-feira, 1 de Agosto de 2007 11:24
To: Gustav Wiberg
Cc: 'Mark Abrams'; 'php-windows@lists.php.net'
Subject: Re: [PHP-WIN] ORDER BY is not sorting
Gustav Wiberg wrote:
> Hi!
>
> I can't see anything with your code either. Mysql_fetch_array should work
fine yes. No indexes are needed to sort fields, but are recommended for
speeding up the process :-)
>
> How does the table users look like? (Please send a link to a screenshot or
something like that)
>
> Sometimes I have noticed that PHP isn't that good of getting right results
when using $variable inside ""-chars
what do you mean by that??? You mean PHP is having trouble getting
'right results' from a mysql database if _somewhere_ in the code there's
an interpolated string? Sounds a bit iffy to me...
- Tul
>
>
> You could try doing this:
>
> $table_name ='users';
>
> // Select records
> $result = mysql_query("SELECT * FROM " . $table_name . " ORDER BY
rowID DESC");
>
>
> // Loop through the record set
> while($row = mysql_fetch_array($result))
> print 'rowID =' .$row['rowID']. '
'
>
>
> There might be some issues regarding permissons of MySQL. Have you tried
doing another sql-select statement on another table?
>
> Best regards
> /Gustav Wiberg
>
>
>
>
> -----Original Message-----
> From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
> Sent: Wednesday, August 01, 2007 12:50 AM
> To: php-windows@lists.php.net
> Subject: Re: [PHP-WIN] ORDER BY is not sorting
>
> Is mysql_fetch_array the proper function to access sorted data? The
> problem is consistent on my test server and my ISPs mySQL DB.
>
> rowID is the primary key. Do I need to have an index attribute on a field
I
> want to sort?
>
>
>
>
> wrote in message
> news:20070731203155.CEE1819504F@spaceymail-a3.g.dreamhost.co m...
>> I can't really see anything wrong with what you have there. It shouldn't
>> matter that your SQL is inside the query function, although I like to
build
>> the query in a variable outside the query function, but either way it
>> should work.
>>
>> And you're obviously getting data and not an error, right?
>>
>> What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1?
>> or still 1, 2, 3, 4?
>>
>> You might try displaying more data from the result set to see if there's
>> some other issue.
>>
>> And have you tested the SQL statement just using MySQL via command line,
>> phpMyAdmin, WinSQL, Navicat, or something like that?
>>
>> -TG
>>
>> = = = Original message = = =
>>
>> Sorry, this seams very trivial but I can not sort the result set for any
>> field. What am I doing wrong?
>>
>>
>> php & mySQL 5
>>
>>
>>
>>
>> ...
>>
>> $table_name ='users';
>>
>> // Select records
>> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID
DESC");
>>
>>
>> // Loop through the record set
>> while($row = mysql_fetch_array($result))
>> print 'rowID =' .$row['rowID']. '
'
>>
>>
>> ?>
>>
>> 1
>> 2
>> 3
>> 4
>>
>>
>> TIA
>> Mark
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> ___________________________________________________________
>> Sent by ePrompter, the premier email notification software.
>> Free download at http://www.ePrompter.com.
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Solved - Re: [PHP-WIN] ORDER BY is not sorting
am 01.08.2007 15:59:15 von Mark Abrams
Thank you all. Problem solved.
Gustav, I followed your recomendation and changed the table name var to the
actual table name and my problem is solved. Perpaps something is lost in the
interperter when PHP passes the code.
It has been this group that helps make working with PHP fun.
"Gustav Wiberg" wrote in message
news:6E.E1.12911.71320B64@pb1.pair.com...
Hi!
I can't see anything with your code either. Mysql_fetch_array should work
fine yes. No indexes are needed to sort fields, but are recommended for
speeding up the process :-)
How does the table users look like? (Please send a link to a screenshot or
something like that)
Sometimes I have noticed that PHP isn't that good of getting right results
when using $variable inside ""-chars
You could try doing this:
$table_name ='users';
// Select records
$result = mysql_query("SELECT * FROM " . $table_name . " ORDER BY rowID
DESC");
// Loop through the record set
while($row = mysql_fetch_array($result))
print 'rowID =' .$row['rowID']. '
'
There might be some issues regarding permissons of MySQL. Have you tried
doing another sql-select statement on another table?
Best regards
/Gustav Wiberg
-----Original Message-----
From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
Sent: Wednesday, August 01, 2007 12:50 AM
To: php-windows@lists.php.net
Subject: Re: [PHP-WIN] ORDER BY is not sorting
Is mysql_fetch_array the proper function to access sorted data? The
problem is consistent on my test server and my ISPs mySQL DB.
rowID is the primary key. Do I need to have an index attribute on a field I
want to sort?
wrote in message
news:20070731203155.CEE1819504F@spaceymail-a3.g.dreamhost.co m...
>I can't really see anything wrong with what you have there. It shouldn't
>matter that your SQL is inside the query function, although I like to build
>the query in a variable outside the query function, but either way it
>should work.
>
> And you're obviously getting data and not an error, right?
>
> What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1?
> or still 1, 2, 3, 4?
>
> You might try displaying more data from the result set to see if there's
> some other issue.
>
> And have you tested the SQL statement just using MySQL via command line,
> phpMyAdmin, WinSQL, Navicat, or something like that?
>
> -TG
>
> = = = Original message = = =
>
> Sorry, this seams very trivial but I can not sort the result set for any
> field. What am I doing wrong?
>
>
> php & mySQL 5
>
>
>
>
> ...
>
> $table_name ='users';
>
> // Select records
> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
>
>
> // Loop through the record set
> while($row = mysql_fetch_array($result))
> print 'rowID =' .$row['rowID']. '
'
>
>
> ?>
>
> 1
> 2
> 3
> 4
>
>
> TIA
> Mark
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> ___________________________________________________________
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.11.0/927 - Release Date: 2007-07-30
17:02
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Solved - Re: [PHP-WIN] ORDER BY is not sorting
am 01.08.2007 16:13:47 von Tom Hearn
Mark,
I have another suggestion for you to try, you can use this while
using post variables, and class-access variables.
$result = mysql_query("SELECT * FROM {$table_name} ORDER BY rowID
DESC");
This is doing the exact same thing as your previous statement, but
it allows you to remove the parenthesis and you can also do nifty things
like
{$_myclass->getuserid()} without having to escape it with parenthesis.
Another thing to check, do you have register_globals set to on?
Your PHP may be requiring you to access $table_name as $_GET["table_name"]
or $_POST["table_name"]?
Cheers,
Tom Hearn
Software Engineer
N Software
http://www.nsoftware.com
-----Original Message-----
From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
Sent: Wednesday, August 01, 2007 9:59 AM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Solved - Re: [PHP-WIN] ORDER BY is not sorting
Thank you all. Problem solved.
Gustav, I followed your recomendation and changed the table name var to the
actual table name and my problem is solved. Perpaps something is lost in the
interperter when PHP passes the code.
It has been this group that helps make working with PHP fun.
"Gustav Wiberg" wrote in message
news:6E.E1.12911.71320B64@pb1.pair.com...
Hi!
I can't see anything with your code either. Mysql_fetch_array should work
fine yes. No indexes are needed to sort fields, but are recommended for
speeding up the process :-)
How does the table users look like? (Please send a link to a screenshot or
something like that)
Sometimes I have noticed that PHP isn't that good of getting right results
when using $variable inside ""-chars
You could try doing this:
$table_name ='users';
// Select records
$result = mysql_query("SELECT * FROM " . $table_name . " ORDER BY rowID
DESC");
// Loop through the record set
while($row = mysql_fetch_array($result))
print 'rowID =' .$row['rowID']. '
'
There might be some issues regarding permissons of MySQL. Have you tried
doing another sql-select statement on another table?
Best regards
/Gustav Wiberg
-----Original Message-----
From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
Sent: Wednesday, August 01, 2007 12:50 AM
To: php-windows@lists.php.net
Subject: Re: [PHP-WIN] ORDER BY is not sorting
Is mysql_fetch_array the proper function to access sorted data? The
problem is consistent on my test server and my ISPs mySQL DB.
rowID is the primary key. Do I need to have an index attribute on a field I
want to sort?
wrote in message
news:20070731203155.CEE1819504F@spaceymail-a3.g.dreamhost.co m...
>I can't really see anything wrong with what you have there. It shouldn't
>matter that your SQL is inside the query function, although I like to build
>the query in a variable outside the query function, but either way it
>should work.
>
> And you're obviously getting data and not an error, right?
>
> What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1?
> or still 1, 2, 3, 4?
>
> You might try displaying more data from the result set to see if there's
> some other issue.
>
> And have you tested the SQL statement just using MySQL via command line,
> phpMyAdmin, WinSQL, Navicat, or something like that?
>
> -TG
>
> = = = Original message = = =
>
> Sorry, this seams very trivial but I can not sort the result set for any
> field. What am I doing wrong?
>
>
> php & mySQL 5
>
>
>
>
> ...
>
> $table_name ='users';
>
> // Select records
> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
>
>
> // Loop through the record set
> while($row = mysql_fetch_array($result))
> print 'rowID =' .$row['rowID']. '
'
>
>
> ?>
>
> 1
> 2
> 3
> 4
>
>
> TIA
> Mark
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> ___________________________________________________________
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.11.0/927 - Release Date: 2007-07-30
17:02
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.11.0/929 - Release Date: 7/31/2007
5:26 PM
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.11.0/929 - Release Date: 7/31/2007
5:26 PM
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Solved - Re: [PHP-WIN] ORDER BY is not sorting
am 03.08.2007 20:51:26 von Dijital
I've seen this issue before as well.. if you want to keep the
$table_name variable in there in order to maintain dynamics, try
escaping first and it should work fine. Your modified query would look
like this:
$result = mysql_query("SELECT * FROM ". $table_name ." ORDER BY rowID
DESC");
Cheers.
Armando
Mark Abrams wrote:
> Thank you all. Problem solved.
>
> Gustav, I followed your recomendation and changed the table name var to the
> actual table name and my problem is solved. Perpaps something is lost in the
> interperter when PHP passes the code.
>
> It has been this group that helps make working with PHP fun.
>
> "Gustav Wiberg" wrote in message
> news:6E.E1.12911.71320B64@pb1.pair.com...
> Hi!
>
> I can't see anything with your code either. Mysql_fetch_array should work
> fine yes. No indexes are needed to sort fields, but are recommended for
> speeding up the process :-)
>
> How does the table users look like? (Please send a link to a screenshot or
> something like that)
>
> Sometimes I have noticed that PHP isn't that good of getting right results
> when using $variable inside ""-chars
>
>
> You could try doing this:
>
> $table_name ='users';
>
> // Select records
> $result = mysql_query("SELECT * FROM " . $table_name . " ORDER BY rowID
> DESC");
>
>
> // Loop through the record set
> while($row = mysql_fetch_array($result))
> print 'rowID =' .$row['rowID']. '
'
>
>
> There might be some issues regarding permissons of MySQL. Have you tried
> doing another sql-select statement on another table?
>
> Best regards
> /Gustav Wiberg
>
>
>
>
> -----Original Message-----
> From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
> Sent: Wednesday, August 01, 2007 12:50 AM
> To: php-windows@lists.php.net
> Subject: Re: [PHP-WIN] ORDER BY is not sorting
>
> Is mysql_fetch_array the proper function to access sorted data? The
> problem is consistent on my test server and my ISPs mySQL DB.
>
> rowID is the primary key. Do I need to have an index attribute on a field I
> want to sort?
>
>
>
>
> wrote in message
> news:20070731203155.CEE1819504F@spaceymail-a3.g.dreamhost.co m...
>> I can't really see anything wrong with what you have there. It shouldn't
>> matter that your SQL is inside the query function, although I like to build
>> the query in a variable outside the query function, but either way it
>> should work.
>>
>> And you're obviously getting data and not an error, right?
>>
>> What happens if you leave the "DESC" off? Does it come back 4, 3, 2, 1?
>> or still 1, 2, 3, 4?
>>
>> You might try displaying more data from the result set to see if there's
>> some other issue.
>>
>> And have you tested the SQL statement just using MySQL via command line,
>> phpMyAdmin, WinSQL, Navicat, or something like that?
>>
>> -TG
>>
>> = = = Original message = = =
>>
>> Sorry, this seams very trivial but I can not sort the result set for any
>> field. What am I doing wrong?
>>
>>
>> php & mySQL 5
>>
>>
>>
>>
>> ...
>>
>> $table_name ='users';
>>
>> // Select records
>> $result = mysql_query("SELECT * FROM $table_name ORDER BY rowID DESC");
>>
>>
>> // Loop through the record set
>> while($row = mysql_fetch_array($result))
>> print 'rowID =' .$row['rowID']. '
'
>>
>>
>> ?>
>>
>> 1
>> 2
>> 3
>> 4
>>
>>
>> TIA
>> Mark
>>
>> --
>> PHP Windows Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> ___________________________________________________________
>> Sent by ePrompter, the premier email notification software.
>> Free download at http://www.ePrompter.com.
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php