Re: reverse array for mysql data

From: Date: Tue, 01 May 2001 23:11:35 +0000
Subject: Re: reverse array for mysql data
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-51051@lists.php.net to get a copy of this message
> 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) maybe, you add an ORDER BY clause to your query. This cause that returning rows in the result set are ordered in that way you 've specified. ORDER BY works as follows : ORDER BY <column name> ASC for ascending or DESC for descending sorting. (you can give more than one column name.) $result = mysql_query ("SELECT title, body FROM junkyard ORDER BY title DESC LIMIT 0, 7"); or you can gather all the rows you need in an array and print this array as you love. for ($i = 0 ; $i < 7 && ($result_rows[] = mysql_fetch_array($result)); $i++) ; > $i = '0'; > > while ($i < 7) { > if ($row = mysql_fetch_array ($result)) { > echo "$row[0] <br />$row[1]"; > ++$i; > } > } >

« previous php.general (#51051) next »