1

I'm doing some database query and I want a automatic system but I encounter this when getting the list of tables with the query.

SHOW TABLES ;

Using Php to get this function returns the array of tables now just the values like Person. It is posible to get only the result?

   $rows = Array();
while($row = mysql_fetch_array($result)){
  array_push($rows, $row);
}
echo json_encode($rows);

Result

[{"0":"Company","Tables_in_database":"Company"},{"0":"Education","Tables_in_database":"Education"},{"0":"Health","Tables_in_database":"Health"},{"0":"Person","Tables_in_database":"Person"},{"0":"Personal","Tables_in_database":"Personal"},{"0":"Skill","Tables_in_database":"Skill"}]

I only want the values: Company, Education, Health, ETC.

  • I didn't understand your question. What exactly you want? – al'ein Oct 15 '15 at 20:18
  • I did not understand it either! – Shadow Oct 15 '15 at 20:18
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Oct 15 '15 at 20:19
  • I updated the question with the result guys. Thanks for reply – Giovannie Sanchez Diaz Oct 15 '15 at 20:20
  • 1
    `array_push($rows, $row['Tables_in_database']);`? – al'ein Oct 15 '15 at 20:23
  • Thanks Alan it works the selection – Giovannie Sanchez Diaz Oct 15 '15 at 20:29

1 Answers1

0

$row is an array containing all the columns in the results. Since you just want one column, select it explicitly.

array_push($rows, $row['Tables_in_database']);
Barmar
  • 741,623
  • 53
  • 500
  • 612