RE: [PHP] Using MySQL user variables in PHP
| From: | John W. Holmes | Date: | Sun, 26 Jan 2003 18:29:52 +0000 |
| Subject: | RE: [PHP] Using MySQL user variables in PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-133183@lists.php.net to get a copy of this message | ||
> I'm currently developing a PHP/MySQL project, one aspect of which
> involves displaying a default set from the database which picks out
all
> records for whichever individual is associated with the most recent
> date. I know this is a very general description, but I don't think
it's
> necessary to burden list members with further detail, nor to pass on
> details of my table structures.
>
> Suffice it to say that I successfully achieved my goal with MySQL from
> the command line, but I'm not sure how to write this functionality
into
> my PHP code.
>
> In MySQL, the following sequence of commands works the magic:
>
> SELECT @most_recent:=MAX(date)
> FROM presenters;
>
> SELECT @recent_presenter:=presenter
> FROM presenters
> WHERE date = @most_recent;
>
> SELECT p.date, p.theme, p.presenter,
> c.itemNo, c.composer, c.composition, c.note
> FROM presenters p, compositions c
> WHERE p.date = c.date AND p.presenter =
@recent_presenter
> ORDER BY p.date DESC;
>
> So how do I transfer all this to PHP?
Pretty sure you can do all that with one query. Something like:
SELECT p.date, p.theme, p.presenter,
c.itemNo, c.composer, c.composition, c.note
FROM presenters p, compositions c
WHERE p.date = c.date
ORDER BY p.date DESC LIMIT 1
Not sure, though, as I don't have time to test right now.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/