-7

php code snippet here

<?php
  $messages = mysql_query("SELECT * FROM privatemessages WHERE nodeview='$_GET[nodeview]' ORDER BY id ASC LIMIT 5 OFFSET $_GET[offset]");
  while($message = mysql_fetch_array( $messages )) {
  $user = mysql_query("SELECT * FROM users WHERE id='$message[senderuserid]' ");
  $user = mysql_fetch_array($user);
  $rows[] = $message[message];


  }
  print_r($rows);
  array_reverse($rows);
  print_r($rows);

  ?>

Why does it reverse some arrays but not others?

desbest
  • 4,746
  • 11
  • 51
  • 84
  • 2
    Please post your code as text, formatted to a code block, rather than as an image. Likewise, post your output sample as text. – Michael Berkowski Jul 22 '15 at 23:50
  • 1
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jul 22 '15 at 23:50
  • My webhost uses mod_security so I'm not vulnerable to SQL injection attacks. I will use an ORM such as TBSsql or Medoo once the php upgrade breaks my scripts. – desbest Jul 22 '15 at 23:52
  • mod_security is a blacklist. It covers known and a few generic exploits. But its ruleset is by no means clever enough to prevent all kinds of data tampering and code injections. – mario Jul 22 '15 at 23:54
  • I tried to sql injection my own website that I coded and it gave me a 406 Not Acceptable error when I tried to, so I suppose that my web host is protected against sql injection. – desbest Jul 23 '15 at 00:01

1 Answers1

7

array_reverse — Return an array with elements in reverse order

It returns the reversed array, but does not reverse it "in place"

$rows = array_reverse($rows);
dave
  • 62,300
  • 5
  • 72
  • 93