0

I'm having trouble unpacking data from MySQL.

Here is my code

if($result){

 $sql_result = mysql_query("SELECT * FROM  `application` ORDER BY  `application`.`app_id`               
 DESC LIMIT 0 , 1");
 $row = mysql_fetch_row($sql_result); 
 echo $row['app_id'];

  }

  else {
  echo "ERROR";
  }

This should echo the app_id but, the page is just returning blank. Any ideas? Thanks.

Mark charlton
  • 377
  • 3
  • 15
  • Try `$row[0]['app_id']` –  Nov 19 '13 at 08:40
  • 1
    [The `mysql_xxx` functions are deprecated. Do not use them for new code.](http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-removed-in-the-future-use-mysqli) – Jonathon Reinhart Nov 19 '13 at 08:41

3 Answers3

0

mysql_fetch_row() will return result as numerical array. So you need to fetch the result with index like $row[0]. If you are using mysql_fetch_array(), it will result an associative array where you can either use numerical index or field index as $row['app_id'].

Jenz
  • 8,280
  • 7
  • 44
  • 77
0

Change it to

$row = mysql_fetch_assoc($sql_result); 
Mihai
  • 26,325
  • 7
  • 66
  • 81
0

mysql_fetch_row ($result ) Returns a numerical array that corresponds to the fetched row and moves the internal data pointer ahead.

use echo $row['0']; instead of echo $row['app_id'];

Krish R
  • 22,583
  • 7
  • 50
  • 59