Re: [PHP] Getting Newest

2002-11-07 Thread Maxim Maletsky

SELECT * FROM table ORDER BY date DESC


--
Maxim Maletsky
[EMAIL PROTECTED]



Stephen [EMAIL PROTECTED] wrote... :

 Sorry, I'm using MySQL.
 
 
 - Original Message -
 From: Marco Tabini [EMAIL PROTECTED]
 To: Stephen [EMAIL PROTECTED]
 Cc: PHP List [EMAIL PROTECTED]
 Sent: Wednesday, November 06, 2002 4:00 PM
 Subject: Re: [PHP] Getting Newest
 
 
  That depends on what DBMS you are using. Which one is it?
 
 
  Marco
  --
  
  php|architect - The magazine for PHP Professionals
  The first monthly worldwide  magazine dedicated to PHP programmer
 
  Come visit us at http://www.phparch.com!
 
 
 
 
 
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-07 Thread Stephen
Did you not read what I asked? I have three tables, I need to get the newest
from whichever table has the newest piece of content.


- Original Message -
From: Maxim Maletsky [EMAIL PROTECTED]
To: Stephen [EMAIL PROTECTED]
Cc: PHP List [EMAIL PROTECTED]
Sent: Thursday, November 07, 2002 12:46 PM
Subject: Re: [PHP] Getting Newest



 SELECT * FROM table ORDER BY date DESC


 --
 Maxim Maletsky
 [EMAIL PROTECTED]



 Stephen [EMAIL PROTECTED] wrote... :

  Sorry, I'm using MySQL.
 
 
  - Original Message -
  From: Marco Tabini [EMAIL PROTECTED]
  To: Stephen [EMAIL PROTECTED]
  Cc: PHP List [EMAIL PROTECTED]
  Sent: Wednesday, November 06, 2002 4:00 PM
  Subject: Re: [PHP] Getting Newest
 
 
   That depends on what DBMS you are using. Which one is it?
  
  
   Marco
   --
   
   php|architect - The magazine for PHP Professionals
   The first monthly worldwide  magazine dedicated to PHP programmer
  
   Come visit us at http://www.phparch.com!
  
  
 
 

 --
--
  
 
 
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-07 Thread .: B i g D o g :.
Why cant u do a query with some subselects and verify the date from each
one or do three queryies for the newest one and then compare them with
each other...

Should be relatively simple...


However, it would be better if the date where a timestamp...MHO



On Wed, 2002-11-06 at 21:10, Stephen wrote:
 I have three tables with certain content in each that's added almost daily. I want 
to get the most recent, out of those three tables, and then display it. How would I 
do that without changing the structure of my tables? (My current structure is this: 
id, date, name, text)
 
 Thanks,
 Stephen Craton
 http://www.melchior.us
 
 Life is a gift from God. Wasting it is like destroying your favorite item you 
received from the person you love most. -- www.melchior.us
-- 
.: B i g D o g :.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-07 Thread Miles Thompson
Lighten up! Participation here is voluntary.

Maxim gave you a good answer, as you provided no information about the 
table structure. I'd be wondering why you are using three tables, but 
that's probably another discussion. Based on what he gave you, and a little 
study you should be able to figure it out, otherwise query each table in 
turn  pick the most recent according to whatever criteria you use.

Have an index on the field which determines most recent, check the max() 
function and side effects it may have on query speed.

Cheers - Miles Thompson

PS Why do you have three tables - is your data fully normalized?

At 03:19 PM 11/7/2002 -0500, Stephen wrote:
Did you not read what I asked? I have three tables, I need to get the newest
from whichever table has the newest piece of content.


- Original Message -
From: Maxim Maletsky [EMAIL PROTECTED]
To: Stephen [EMAIL PROTECTED]
Cc: PHP List [EMAIL PROTECTED]
Sent: Thursday, November 07, 2002 12:46 PM
Subject: Re: [PHP] Getting Newest



 SELECT * FROM table ORDER BY date DESC


 --
 Maxim Maletsky
 [EMAIL PROTECTED]



 Stephen [EMAIL PROTECTED] wrote... :

  Sorry, I'm using MySQL.
 
 
  - Original Message -
  From: Marco Tabini [EMAIL PROTECTED]
  To: Stephen [EMAIL PROTECTED]
  Cc: PHP List [EMAIL PROTECTED]
  Sent: Wednesday, November 06, 2002 4:00 PM
  Subject: Re: [PHP] Getting Newest
 
 
   That depends on what DBMS you are using. Which one is it?
  
  
   Marco
   --
   
   php|architect - The magazine for PHP Professionals
   The first monthly worldwide  magazine dedicated to PHP programmer
  
   Come visit us at http://www.phparch.com!
  
  
 
 

 --
--
  
 
 
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-06 Thread Marco Tabini
That depends on what DBMS you are using. Which one is it?


Marco
-- 

php|architect - The magazine for PHP Professionals
The first monthly worldwide  magazine dedicated to PHP programmer

Come visit us at http://www.phparch.com!


---BeginMessage---
I have three tables with certain content in each that's added almost daily. I want to 
get the most recent, out of those three tables, and then display it. How would I do 
that without changing the structure of my tables? (My current structure is this: id, 
date, name, text)

Thanks,
Stephen Craton
http://www.melchior.us

Life is a gift from God. Wasting it is like destroying your favorite item you 
received from the person you love most. -- www.melchior.us
---End Message---
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Getting Newest

2002-11-06 Thread Stephen
Sorry, I'm using MySQL.


- Original Message -
From: Marco Tabini [EMAIL PROTECTED]
To: Stephen [EMAIL PROTECTED]
Cc: PHP List [EMAIL PROTECTED]
Sent: Wednesday, November 06, 2002 4:00 PM
Subject: Re: [PHP] Getting Newest


 That depends on what DBMS you are using. Which one is it?


 Marco
 --
 
 php|architect - The magazine for PHP Professionals
 The first monthly worldwide  magazine dedicated to PHP programmer

 Come visit us at http://www.phparch.com!








 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-06 Thread Stephen
I know that you can select data from multiple tables, but when I do that I
get an error. The error is this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in /usr/local/plesk/apache/vhosts/melchior.us/httpdocs/live/all.php
on line 17

- Original Message -
From: Marco Tabini [EMAIL PROTECTED]
To: Stephen [EMAIL PROTECTED]
Sent: Wednesday, November 06, 2002 4:44 PM
Subject: Re: [PHP] Getting Newest


 I think you would need to make three queries, since Mysql doesn't
 support subqueries... or am I wrong?


 Marco

 --
 
 php|architect - The magazine for PHP Professionals
 The first monthly worldwide  magazine dedicated to PHP programmer

 Come visit us at http://www.phparch.com!




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-06 Thread Marco Tabini
That's probably because you can't do it in a single SQL statement, but
have to use three separate ones and build the logic to check which one
is the most recent in PHP. Try outputting the query and posting it to
the list, or try inserting a line like this:

echo mysql_error();

after you execute your query--that will print out what the MySQL server
thinks is wrong with your current query.

Hope this helps!

Cheers,


Marco

-- 

php|architect - The magazine for PHP Professionals
The first monthly worldwide  magazine dedicated to PHP programmer

Come visit us at http://www.phparch.com!


---BeginMessage---
I know that you can select data from multiple tables, but when I do that I
get an error. The error is this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in /usr/local/plesk/apache/vhosts/melchior.us/httpdocs/live/all.php
on line 17

- Original Message -
From: Marco Tabini [EMAIL PROTECTED]
To: Stephen [EMAIL PROTECTED]
Sent: Wednesday, November 06, 2002 4:44 PM
Subject: Re: [PHP] Getting Newest


 I think you would need to make three queries, since Mysql doesn't
 support subqueries... or am I wrong?


 Marco

 --
 
 php|architect - The magazine for PHP Professionals
 The first monthly worldwide  magazine dedicated to PHP programmer

 Come visit us at http://www.phparch.com!




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



---End Message---
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Getting Newest

2002-11-06 Thread 1LT John W. Holmes
Are all three tables the same? Same columns and everything?

---John Holmes...

- Original Message -
From: Stephen [EMAIL PROTECTED]
To: PHP List [EMAIL PROTECTED]
Sent: Wednesday, November 06, 2002 4:10 PM
Subject: [PHP] Getting Newest


I have three tables with certain content in each that's added almost daily.
I want to get the most recent, out of those three tables, and then display
it. How would I do that without changing the structure of my tables? (My
current structure is this: id, date, name, text)

Thanks,
Stephen Craton
http://www.melchior.us

Life is a gift from God. Wasting it is like destroying your favorite item
you received from the person you love most. -- www.melchior.us


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-06 Thread Stephen
Yes, same columns, everything the same except names and content.


- Original Message -
From: 1LT John W. Holmes [EMAIL PROTECTED]
To: Stephen [EMAIL PROTECTED]; PHP List
[EMAIL PROTECTED]
Sent: Wednesday, November 06, 2002 5:31 PM
Subject: Re: [PHP] Getting Newest


 Are all three tables the same? Same columns and everything?

 ---John Holmes...

 - Original Message -
 From: Stephen [EMAIL PROTECTED]
 To: PHP List [EMAIL PROTECTED]
 Sent: Wednesday, November 06, 2002 4:10 PM
 Subject: [PHP] Getting Newest


 I have three tables with certain content in each that's added almost
daily.
 I want to get the most recent, out of those three tables, and then display
 it. How would I do that without changing the structure of my tables? (My
 current structure is this: id, date, name, text)

 Thanks,
 Stephen Craton
 http://www.melchior.us

 Life is a gift from God. Wasting it is like destroying your favorite item
 you received from the person you love most. -- www.melchior.us


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-06 Thread Nick Eby
you could make a union of all the records, and order by newest date first:

(select id, date, name, text from table1) union
(select id, date, name, text from table2) union
(select id, date, name, text from table3) order by date desc

then select the first record
/nick



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-06 Thread Stephen
So for my SQL statement I put this?

$sql = select id, date, name, text from table1 union;
$sql2 = select id, date, name, text from table2 union;
$sql3 = select id, date, name, text from table3 order by date desc;


- Original Message -
From: Nick Eby [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, November 06, 2002 7:57 PM
Subject: Re: [PHP] Getting Newest


 you could make a union of all the records, and order by newest date first:

 (select id, date, name, text from table1) union
 (select id, date, name, text from table2) union
 (select id, date, name, text from table3) order by date desc

 then select the first record
 /nick



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Getting Newest

2002-11-06 Thread John W. Holmes
 $sql = select id, date, name, text from table1 union;
 $sql2 = select id, date, name, text from table2 union;
 $sql3 = select id, date, name, text from table3 order by date desc;


No, it's all one query. 

$sql = select id, date, name, text from table1 union 
  .select id, date, name, text from table2 union 
  .select id, date, name, text from table3 order by date desc;

---John Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Getting Newest

2002-11-06 Thread John W. Holmes
UNION is implemented in MySQL 4.0.0, btw.

 -Original Message-
 From: Stephen [mailto:webmaster;melchior.us]
 Sent: Wednesday, November 06, 2002 9:33 PM
 To: PHP List
 Subject: Re: [PHP] Getting Newest
 
 So for my SQL statement I put this?
 
 $sql = select id, date, name, text from table1 union;
 $sql2 = select id, date, name, text from table2 union;
 $sql3 = select id, date, name, text from table3 order by date desc;
 
 
 - Original Message -
 From: Nick Eby [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Wednesday, November 06, 2002 7:57 PM
 Subject: Re: [PHP] Getting Newest
 
 
  you could make a union of all the records, and order by newest date
 first:
 
  (select id, date, name, text from table1) union
  (select id, date, name, text from table2) union
  (select id, date, name, text from table3) order by date desc
 
  then select the first record
  /nick
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Getting Newest

2002-11-06 Thread Stephen
Oh, well, now I'm getting this error:

You have an error in your SQL syntax near 'union select * from church union
select * from misc order by date desc limit 1' at line 1

Here's what I did for the SQL

$sql = select * from school union ;
$sql .= select * from church union ;
$sql .= select * from misc order by date desc limit 1;


- Original Message -
From: John W. Holmes [EMAIL PROTECTED]
To: 'Stephen' [EMAIL PROTECTED]; 'PHP List'
[EMAIL PROTECTED]
Sent: Wednesday, November 06, 2002 9:43 PM
Subject: RE: [PHP] Getting Newest


 UNION is implemented in MySQL 4.0.0, btw.

  -Original Message-
  From: Stephen [mailto:webmaster;melchior.us]
  Sent: Wednesday, November 06, 2002 9:33 PM
  To: PHP List
  Subject: Re: [PHP] Getting Newest
 
  So for my SQL statement I put this?
 
  $sql = select id, date, name, text from table1 union;
  $sql2 = select id, date, name, text from table2 union;
  $sql3 = select id, date, name, text from table3 order by date desc;
 
 
  - Original Message -
  From: Nick Eby [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Wednesday, November 06, 2002 7:57 PM
  Subject: Re: [PHP] Getting Newest
 
 
   you could make a union of all the records, and order by newest date
  first:
  
   (select id, date, name, text from table1) union
   (select id, date, name, text from table2) union
   (select id, date, name, text from table3) order by date desc
  
   then select the first record
   /nick
  
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Getting Newest

2002-11-06 Thread John W. Holmes
Read my last post and then run SELECT VERSION() in MySQL. I really doubt
you're running 4.0. 

---John Holmes...

 -Original Message-
 From: Stephen [mailto:webmaster;melchior.us]
 Sent: Wednesday, November 06, 2002 9:57 PM
 To: PHP List
 Subject: Re: [PHP] Getting Newest
 
 Oh, well, now I'm getting this error:
 
 You have an error in your SQL syntax near 'union select * from church
 union
 select * from misc order by date desc limit 1' at line 1
 
 Here's what I did for the SQL
 
 $sql = select * from school union ;
 $sql .= select * from church union ;
 $sql .= select * from misc order by date desc limit 1;
 
 
 - Original Message -
 From: John W. Holmes [EMAIL PROTECTED]
 To: 'Stephen' [EMAIL PROTECTED]; 'PHP List'
 [EMAIL PROTECTED]
 Sent: Wednesday, November 06, 2002 9:43 PM
 Subject: RE: [PHP] Getting Newest
 
 
  UNION is implemented in MySQL 4.0.0, btw.
 
   -Original Message-
   From: Stephen [mailto:webmaster;melchior.us]
   Sent: Wednesday, November 06, 2002 9:33 PM
   To: PHP List
   Subject: Re: [PHP] Getting Newest
  
   So for my SQL statement I put this?
  
   $sql = select id, date, name, text from table1 union;
   $sql2 = select id, date, name, text from table2 union;
   $sql3 = select id, date, name, text from table3 order by date
desc;
  
  
   - Original Message -
   From: Nick Eby [EMAIL PROTECTED]
   To: [EMAIL PROTECTED]
   Sent: Wednesday, November 06, 2002 7:57 PM
   Subject: Re: [PHP] Getting Newest
  
  
you could make a union of all the records, and order by newest
date
   first:
   
(select id, date, name, text from table1) union
(select id, date, name, text from table2) union
(select id, date, name, text from table3) order by date desc
   
then select the first record
/nick
   
   
   
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
   
   
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php