Re: ORDER BY is not sorting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <space>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@xxxxxxxxxxxxxxxxxxxxxx <tg-php@xxxxxxxxxxxxxxxxxxxxxx>
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
>
>
> <?php
>
> ...
>
>    $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']. '<br />'
>
>
> ?>
>
> 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@xxxxxxxxx
MSN brunopolicarpo@xxxxxxxxxxx


___________________________________________________________
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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux