1

I have a problem with a view call in php:

 $query = "SELECT * FROM contact_numers_view";
 $result=mysql_fetch_array(mysql_query($query));
 //conversion from array to string
 $separater = implode(",", $result);

on echo $separater I should get a number 100020 but instead of this I get it doubled like 100020, 100020

Any hint about what is wrong?

The view is:

CREATE VIEW contact_numers_view AS
            SELECT COUNT(*) FROM contacts;
SilenceIsGolden
  • 59
  • 1
  • 1
  • 6

1 Answers1

1

mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both

see http://in3.php.net/mysql_fetch_array

Use result_type as MYSQL_NUM

In you code do as follows,

 $query = "SELECT * FROM contact_numers_view";
 $result=mysql_fetch_array(mysql_query($query), MYSQL_NUM);
 //conversion from array to string
 $separater = implode(",", $result);

And moreover mysql_* functions are officially deprecated (as of PHP 5.5. It's likely to be removed in the next major release)

See here Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
Dushyant Joshi
  • 3,672
  • 3
  • 28
  • 52