Answer the question
In order to leave comments, you need to log in
Sorting in PHP?
There is this code:
$array = array();
for ($count = 1; (($head = mysql_fetch_array($output1)) and ($text = mysql_fetch_array($output2))); ++$count) {
$array[$count] = $head[0];
printf($array[$count]);
echo "<br />";
echo "<br />";
$array[$count] = $text[0];
printf($array[$count]);
echo "<br />";
echo "<br />";
}
return $array;
array_reverse()
, but where did not try to put it here , does not sort.
Answer the question
In order to leave comments, you need to log in
When you get from the database:
SELECT * FROM table_name WHERE (expression) [order by field_name [desc][asc]]
ORDER - there you sort in ascending or descending order (ASC or DESC)
In your case, as I understand it, getting $output1 and $output2 so you do...
This is all of course not entirely ideologically correct, but you need to replace the last line with:
return array_reverse($array);
Then I'll ask another question. Each article must have an id. Let's say for the first article I will specify id=1. How can I take the maximum id element from the database, increase it by one and assign it to a new article? I will sort by id, and for this it is necessary that each subsequent article has one more id.
For this, the autoincrement field type in the database is used
and you can make for not incremental ($i++), but decremental ($i--)
example:
for($i=20,$>=0,$i--){
// ololo
}
Show queries to the database that are made there. There, for sure, after all, one request can be enough ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question