-2

Can anyone explain why running mysql_fetch_array($result,MYSQL_BOTH) on a result sometimes means that key[0] = 0 whilst at other times it ends up with a string/value. See example array below:

Array
(
  [0] => 0
  [groupTitle] => TEST 5
)

In this instance I would expect 0 to equal 'TEST 5'

Ukuser32
  • 2,147
  • 2
  • 22
  • 32
  • You have tried what? It's a very simple thing to do. But we're not here to code for you, only assist in debugging for your learning – Daryl Gill Oct 16 '14 at 11:07
  • Will you write your query here..?? – Shaunak Shukla Oct 16 '14 at 11:07
  • Duplicate of http://stackoverflow.com/questions/17100698/mysql-fetch-array-result-mysql-both-is-not-exact – Shaunak Shukla Oct 16 '14 at 11:08
  • I don't believe it is a duplicate! Example query: SELECT groupTitle FROM db.table WHERE userID = '1' – Ukuser32 Oct 16 '14 at 11:10
  • Single table query doesn't create this kind of issue, If you have used multiple table in query, having same column name in different table, you must use alias to column name.. – Shaunak Shukla Oct 16 '14 at 11:16
  • Yes the full query has got joins but I am referencing it by its table name sappr.groupTitle so therefore this isn't the cause of the problem. – Ukuser32 Oct 16 '14 at 11:27
  • Interestingly as well if I swap the column down to second place then the numeric key does store the string and the first one doesn't. Please revert the downvotes as I'm not fully sure thats fair. – Ukuser32 Oct 16 '14 at 11:29
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource (or mysqli\_result), boolean given](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-or-mysqli-result-boole) – ummahusla Oct 16 '14 at 11:38
  • Nope - completely different. – Ukuser32 Oct 16 '14 at 11:40

1 Answers1

2

The reason was because I wanted Mysql to return '0' as one of the elements/fields. So my query read something like this:

SELECT field1,field2,'0',field3 FROM table

What PHP did was returned the first element in the array with a value '0' but then set the first string key with the correct first element. I believe that may be a bug.

Ukuser32
  • 2,147
  • 2
  • 22
  • 32