Reverse

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Reverse

Post by Silver_Eclipse »

does anyone here know how i would print out something in reverse order?
say i have a list of numbers that is constantly getting larger, how would i print those numbers out from greatest to least instead of least to greatest?
(basically i have info in a database that is numbered and i need to print them all out but in reverse order)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

it's in mysql?

try a query like

SELECT * FROM table ORDER BY column DESC

now, assuming "column" is an integer or something, it will pick out the largest number first, and then descend down to the smallest.
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

Yeah works just fine now, thanks. Another question though, i have a login system setup using cookies, but even if they input an invalid username and password it still sends them a cookie and i have to set the cookies before i can do anything else. Is there a way to make it so that if they input an invalid name and pass then don't send the cookie?
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

or maybe delete the cookie right after the login if the name and password are invalid?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

$qry = mysql_query("SELECT * FROM table WHERE username = '$username' AND password = '$password'");

if(mysql_num_rows($qry) == "1"){
  setcookie();
} else {
  echo "Invalid input";
 }
make sure to do error checking on $username and $password first (like making sure they are just letters and numbers and whatever... you can use regular expressions to do this)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

or use mysql_escape_string on all user input. May they type as much malicious input as they want :D
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

Code: Select all

$qry = mysql_query("SELECT * FROM table WHERE username = '$username' AND password = '$password'"); 

if(mysql_num_rows($qry) == "1"){ 
  setcookie(); 
} else { 
  echo "Invalid input"; 
}
yes but i have to use

Code: Select all

mysql_select_db("db1", $mysql);
to select the database adn tehn i can't set the cookie because it says headers are already sent
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

select_db should not be outputting headers, check for something else.
Post Reply