Fetch Casted Value from a select query into an array

bleyk

I used cast in order to convert a datatype of one of the columns in my select query.

SELECT cast(user_id as varchar(255)) from cabinet

I need to fetch the result of this value into an array but it returns null value

$listData[] = array(
    "member_id" => $row['cast(user_id]
  );

How can I display it on array?

Pyromonk

SQL:

SELECT cast(user_id AS varchar(255)) AS member_id FROM cabinet

PHP:

$listData = array("member_id" => $row['member_id']);

Basically, you forgot to name the cast function's return in your SQL and used some extremely weird syntax in your PHP. $Array[] = $x; adds element $x as an array item to $Array in PHP. To create a new array, you should run $Array = array();. Some programming languages do indeed force you to put square brackets after a variable's name on value assignation to specify it as an Array/String type, but PHP is not one of them.

To reference an item by key, you have to use the array's name and the key's value in square brackets ($Array[$n], where $n is an integer for arrays with integer indexes, and Array['key'] for arrays with String indexes). 'cast(user_id AS varchar(255))' is not a valid array key, you have to give the SQL function return value a name to be able to reference it as an array item.

Please let me know if this makes sense.

My answer assumes that you are familiar with mySQLi and know how to get $row['member_id'] from the query.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

fetch value from an array

From Dev

Mysql: fetch value from database and php array in single query

From Dev

Mysql: fetch value from database and php array in single query

From Dev

fetch value from a given array

From Dev

Fetch value and name in a select, from form

From Dev

Fetch value and name in a select, from form

From Dev

Want to fetch the value of alias from cursor query

From Dev

PHP select from tbl / fetch array issue

From Dev

while($query6=mysql_fetch_array($query5)).How many times it will run?If it select 4 values from the database

From Dev

How to fetch a not so random value from an array?

From Dev

fetch values from different index value in array

From Dev

Not able to fetch correct value from array

From Dev

How to fetch and store value as coordinate from array

From Dev

Fetch a value from an array in a MongoDB collection

From Dev

mysql select query can not fetch data with null value

From Dev

Select rows from the array of another select query

From Dev

What should be casted in the query

From Dev

Update column value with trigger postgresql/ fetch value from insert query

From Dev

fetch value from array within array within array

From Dev

jq select value from array

From Dev

Select query to fetch required data from SQL table

From Dev

How to fetch each value from Array of strings inside an Array

From Dev

Fetch specific array from multidimensional array with matching value php

From Dev

Dynamically fetch value from hashmap during select spark scala

From Dev

How fetch the array from return of query method of a resource in AngularJS?

From Dev

Get record with Max value from SELECT query

From Dev

Get default value from a select in a query

From Dev

Adding value from HTML select into MySQL query

From Dev

Linq query select a particular value from xml

Related Related

  1. 1

    fetch value from an array

  2. 2

    Mysql: fetch value from database and php array in single query

  3. 3

    Mysql: fetch value from database and php array in single query

  4. 4

    fetch value from a given array

  5. 5

    Fetch value and name in a select, from form

  6. 6

    Fetch value and name in a select, from form

  7. 7

    Want to fetch the value of alias from cursor query

  8. 8

    PHP select from tbl / fetch array issue

  9. 9

    while($query6=mysql_fetch_array($query5)).How many times it will run?If it select 4 values from the database

  10. 10

    How to fetch a not so random value from an array?

  11. 11

    fetch values from different index value in array

  12. 12

    Not able to fetch correct value from array

  13. 13

    How to fetch and store value as coordinate from array

  14. 14

    Fetch a value from an array in a MongoDB collection

  15. 15

    mysql select query can not fetch data with null value

  16. 16

    Select rows from the array of another select query

  17. 17

    What should be casted in the query

  18. 18

    Update column value with trigger postgresql/ fetch value from insert query

  19. 19

    fetch value from array within array within array

  20. 20

    jq select value from array

  21. 21

    Select query to fetch required data from SQL table

  22. 22

    How to fetch each value from Array of strings inside an Array

  23. 23

    Fetch specific array from multidimensional array with matching value php

  24. 24

    Dynamically fetch value from hashmap during select spark scala

  25. 25

    How fetch the array from return of query method of a resource in AngularJS?

  26. 26

    Get record with Max value from SELECT query

  27. 27

    Get default value from a select in a query

  28. 28

    Adding value from HTML select into MySQL query

  29. 29

    Linq query select a particular value from xml

HotTag

Archive