You're looking in the wrong place.  What you want to do should be
handled at the database level.  I.e. your SQL query should be something
like:

        select title,body from junkyard order by item_number desc, limit
7

Since you refer to what you want as the 'top 7' entries, there is
presumably some sort of order that you are attempting to enforce in what
you display.  The way you currently have your query formed, the results
you get back are not guaranteed to have any order.  You must add the
order by clause.  

The next problem you're likely to have, is that you don't have any way
of enforcing order in your database other than the item number, which is
probably not what you want.  In this case, what is it that determines
whether something is in the 'top 7'?  Is it based on time?  Is it
alphabetical?  Whatever it is, you need to sort by the corresponding
field.

My guess is that you're going to want to add a timestamp column to your
database, and order by that, descending (i.e. highest to lowest).

Once you do this, you don't need to change your php code at all which
executes the query and displays the results.

Good luck.

Al

> -----Original Message-----
> From: 
> [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED].
> net] On Behalf Of ktb
> Sent: Monday, April 30, 2001 2:52 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] reverse array for mysql data
> 
> 
> I'm new at programing and not getting very far with this.  
> I've looked at "array_revers" and "array_multisort" and can't 
> get anything to work. What I have is a mysql table laid out like:
> 
> item number |  title | body text | subject heading
> 
> What I want to do is pull the top 7 entries off and display 
> them on a web page.  I have written some code that will do 
> this but when it prints to the web page the first item is 
> printed at the top and I would like it on the bottom with 
> later entries successively on top.  How can I do this?  Hear 
> is the code I have so far:
> 
> $result = mysql_query ("SELECT title, body FROM junkyard 
> LIMIT 0, 7"); $i = '0';
> 
> while ($i < 7) {
>     if ($row = mysql_fetch_array ($result)) {
>     echo "$row[0] <br />$row[1]";
>     ++$i;
>     }
> }
> 
> Thanks,
> kent
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: 
> [EMAIL PROTECTED] To contact the list 
> administrators, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to