0

Hello everyone!

I'm wondering if there is a way to assign the values of a column in SQL as the key name in a multidimensional array.

Here is what I have, my database looks like this:

Table Name = SJCFPCB

date | totalin | cdulep | icu |
-----------------------------------
2011-01-27 | 30 | 5 | 4
2011-01-11 | 28 | 4 | 5
2010-12-11 | 31 | 7 | 6

Here is the query I'm using to get the data:

$sql = "SELECT * , convert(CHAR, \"date\", 10) AS ndate from dbo.SJCFPCB where 30 > DATEDIFF(d,\"date\", GETDATE())";
$result=odbc_exec($conn1, $sql);
$DATA=array();

while ($rows=odbc_fetch_array($result)){
$DATA[]=$rows['totalin'];
}
print_r($DATA);

What returns is something like:

Array ( [0] => 30 [1] => 28 [2] => 31)

What I would like to do is rename the keys [0] [1] [2] ect.. .to the value in date field so it would look like this:

Array ( [2011-01-37] => 30 [2011-01-11] => 28 [2010-12-11] => 31)

Any ideas?

Thank you!

Edited by agr8lemon: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by agr8lemon
1

You can make it by assigning the table column as array key.

while ($rows=odbc_fetch_array($result)){
$DATA[$rows['date']]=$rows['totalin'];
}
print_r($DATA);

Edited by paulrajj: n/a

Votes + Comments
Had the perfect solution.
0

You can make it by assigning the table column as array key.

while ($rows=odbc_fetch_array($result)){
$DATA[$rows['date']]=$rows['totalin'];
}
print_r($DATA);

Perfect, Thank you!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.