1

I have this code

$query = "SELECT `subscriberid`,`data` FROM `****table_name*****`"
    . "WHERE `subscriberid` IN (123,456,789,101)";
$result = $cxn->query($query);
$Points = array();
while ($row = $result->fetch_assoc()) {
  $Points[$row['subscriberid']] = $row['data'];
}

I want the keys for $Points to be the subscriberid, but when I print out $Points I keep getting default keys 0-3 and I can't see any reason for this to be happening.

3
  • Are you sure $Points isn't declared somewhere else? ie; it's a unique variable? Also, you could try an alias on the field: "SELECT subscriberid AS sid, data FROM... then use $row['sid'] Commented Mar 6, 2015 at 22:54
  • Can you make a var_dump($Points) please, and a var_dump($row) in between the while loop please. Commented Mar 6, 2015 at 22:57
  • Also, you should only iterate if there was a result; wrap your while... loop in if ($result = $cxn->query($query)) { and } instead of just $result = $cxn->query($query); Commented Mar 6, 2015 at 23:06

1 Answer 1

1

Credits to @Jongosi's Comment, about the if ($result = $cxn->query($query)) part.

Your query is currently as follows:

$query = "SELECT `subscriberid`,`data` FROM `****table_name*****`"
    . "WHERE `subscriberid` IN (123,456,789,101)";

If you only edited ****table_name*****, you are missing a space ( between * and WHERE).

Your result will be nothing or an error.

$query = "SELECT `subscriberid`,`data` FROM `****table_name*****`"
    . " WHERE `subscriberid` IN (123,456,789,101)";
Sign up to request clarification or add additional context in comments.

1 Comment

Well I realized after much testing that I have been writing every thing properly. I printed everything out in a document that resides in the same folder as the class running this method. I found my issue happens when I am using nusoap as a web-service to run those methods across two different servers. I'm thinking nusoap is somehow converting my arrays, because my keys are being reinterpreted and in a totally wrong way. This is still a mystery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.