Re: Table sorting with PHP/MySQL

From: Date: Tue, 30 May 2000 11:35:52 +0000
Subject: Re: Table sorting with PHP/MySQL
Groups: php.general 
Request: Send a blank email to php-general+get-596@lists.php.net to get a copy of this message
What I would do is: 1. SELECT DISTINCT id FROM keyword ORDER BY id You will get 1 2 3 4 as result. 2. Now loop through this result and in every loop do another query that selects all the entries with the id equal to the current loop id $query1="select distinct id from keyword order by id;"; $result1=mysql_query($query1); while ($row1=mysql_fetch_array($result1)) { $index=$row1['id']; $keyword_list[$index]=""; $query2="select * from keyword where id=$index;"; $result2=mysql_query($query2); while ($row2=mysql_fetch_array($result)) { $keyword_list[$index].=$row2['word']." "; //attach next keyword to the string (space-delimited) } } Now you have an array $keyword_list with the ids as key and the keyword sequence as value. Hope it works Steff

« previous php.general (#596) next »