Question

I am writing the result of a database query to an array row by row, then I am adding my own row to the last index of the array. I am using Google developer tools to view the result of the array which are as follows:

10: {strat_id:1, x_id:1, outcome_id:52, date:1364655600, status:0, rank:1,…}
>
strat_id: "1"
status: "0"
date: "1364655600"
x_id: "1"
outcome_id: "52"
rank: "1"

11: {strat_id:4, x_id:1, outcome_id:49, date:1365674916, status:1, rank:1,…}
>
strat_id: 4
status: "1"
date: 1365674916
x_id: 1
outcome_id: 49
rank: 1

The ">" character denotes where I have expanded the index. Index 10 is the last row from the database and as you can see when expanded the values are surround by quotations. Index 11 is data which I have added manually, when expanded as you can see the values are not surrounded by quotations (except for 'status').

In the interests of consistency should I bother with this detail? In order to add to the array I am using:

$newarray=array("strat_id"=>$_POST['gridID']+1, "x_id"=>$_SESSION['xID'], "outcome_id"=>$_POST['cellID']+1, "date"=>time(), "status"=>$_POST['type'], "rank"=>1);

The results of the data base I am getting with:

$result->fetch_array(MYSQLI_ASSOC)

Thanks.

Was it helpful?

Solution

In the interests of consistency should I bother with this detail?

That depends on how you're going to use them. If all you need is display, that's fine; But if you need to do some comparison/calculation (considering you have date value), it would be better to convert them to number.

You may try

$record[]=array_map("intval",$result->fetch_array(MYSQLI_ASSOC));

To make every column as integer, and also later

$record[]=array("strat_id"=>intval($_POST['gridID'])+1,
    "x_id"=>$_SESSION['xID'],
    "outcome_id"=>intval($_POST['cellID'])+1,
    "date"=>time(),
    "status"=>intval($_POST['type']),
    "rank"=>1);

So to have a multidimensional array that has every element as integer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top