Michael

I assume mySQL cant handle the jandal on nested inline queries or common table expressions

either

with lastthirty as (
    Select top 30 *
    From table
    order by datecol desc
)
select * from lastThirty order by keycol

or
SELECT *
FROM
    (
        Select top 30 *
        From table
        order by datecol desc
    ) a
ORDER BY KeyCol

oh the joys of not using mysql

Neven

Nope, I needed to extract the most recent data by date, but then sort it by
keyword once extracted.  This is based on two different fields in the same
table. I do apologise for saying drop it into another table when I am putting
it into an array.

***
$sql = 'SELECT * FROM dbtable WHERE page_url = "' . $_SERVER['PHP_SELF'] . '"
ORDER BY load_date DESC LIMIT 30';
***

This gets the most recently entered data as "load_date" is a DATETIME column.
But then i need to sort it by a seperate column "keyword" alphabetically.
AFAIK (which isn't much) neither SQL or any PHP mysql_XXX functions allow
that, so i need to drop it into an array first then sort the array. It works
with Simons method, I'm good unless someone has something more elegant now i
have explained more.

On Friday 11 March 2011 19:40, Chathura Jayasekara wrote:
INSERT INTO xxxxtable (xxx1field, xxx2field, xxx3fieldl )
SELECT y.xxx1field, y.xxx2field, y.xxx3field  FROM yyy y where {condition}

just do above man with simple mysql_quiry I think this is what need
to simply archive...

CJ

On Fri, Mar 11, 2011 at 10:30 AM, Simon J Welsh<[email protected]>  wrote:
$foo = array();
while($row = mysql_fetch_assoc($result)) {
        $foo[] = $row;
}

Alternatively, array_push($foo, $row); would also work.

On 11/03/2011, at 5:55 PM, Michael Adams wrote:
Is there a simple way to do this so my whole weekend isn't spoiled
worrying

about it.

I want to take all the data from a MySQL query and drop it into another
table.

I tried:
****
       $foo = array( );
       while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
               $foo ->  append($row);
       }
****

But that was a PHP5 solution and even on PHP5 did not seem to like
appending

the first result to an empty array.

This is the best i can do at present which would be extremely wasteful
if
i

had 20 columns in the table instead of the three i am showing here:
****
       $foo = array( );
       $i = 1;
       while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
               $foo[i] = array ('tagID' =>  $row['id'],
                       'date' =>  date("d-m-Y H:i",strtotime
($row['load_date'])),

                       'keyword' =>  htmlspecialchars($row['keywords']))
; i++;
       }
****

TIA

--
Michael

--
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

--
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to