2

Hello stackowerflow people, i need to get array from database, that my variable would look like this $TaskArray['task_id']['task_start_date'] but i dont know how. Maby you guys can help me. Here is the picture of my database enter image description here

Ive tried doing this, but that ddnt worked. Help please.

  $query1 = mysql_query("SELECT task_id, task_start_date FROM dotp_tasks");
  if ($query1) {
      while ($row = mysql_fetch_assoc($query1)) {
        $TaskArray['dbc'] = $row['task_id'];
        $TaskArray['dbc']['task_start_date'] = $row['task_start_date'];
      }
  } else {
2
  • What exactly should the result be? An array with the task ID as the key and the date as value? Commented Jul 23, 2015 at 12:02
  • that is task_id should be dynamic? Commented Jul 23, 2015 at 12:02

2 Answers 2

2

You need to have multi-dimensional array with an array of each task.

...
$query1 = mysql_query("SELECT task_id, task_start_date FROM dotp_tasks");
  if ($query1) {
      while ($row = mysql_fetch_assoc($query1)) {            
        $TaskArray[$row['task_id']]['task_start_date'] = $row['task_start_date'];
      }
  } else {
...

Here, we are generating a multi-dimensional array with task_id as key to each array and that array should contain task details.

Try printing the newly generated array using:

<?php echo '<pre>'; print_r($TaskArray);echo '</pre>';?>
Sign up to request clarification or add additional context in comments.

Comments

1

If I understood your question, this should work:

$query1 = mysql_query("SELECT task_id, task_start_date FROM dotp_tasks");
if ($query1) {
    while ($row = mysql_fetch_assoc($query1)) {
      $TaskArray[$row['task_id']] = $row['task_start_date'];
    }
} else {

Comments

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.