user667340
user667340

Reputation: 531

printing array not working

hello everyone i am printing array from the database in the following format

Array ( [0] => 14
        [task_id] => 14
        [1] => 123
        [user_id] => 123
        [2] => 456
        [employee_id] => 456
        [3] => 2
        [service_id] => 2
        [4] => 2:00 AM
        [starttime] => 2:00 AM
        [5] => 4:00 AM
        [endtime] => 4:00 AM
        [6] => se a
        [servicename] => se a
        [7] => ddsdsd
        [servicedescription] => ddsdsd
        [8] => dsd
        [employeename] => dsd
        [9] => pictures/noimage.gif
        [employeepicture] => pictures/noimage.gif
        [10] => pictures/noimage.gif
        [pic_path] => pictures/noimage.gif ) 

It is the result of

$rd = $this->executeQuery();
$recordsArray = array(); 
while (($row = mysqli_fetch_array($rd)) ){
$recordsArray[] = $row; 

problem is how can i pick the single record from it like this

echo $row[$task_id]; // not working 

Thanks

Upvotes: 0

Views: 538

Answers (6)

Vasu_Sharma
Vasu_Sharma

Reputation: 105

You make a mistake in Syntax
you can try this:

echo $row['task_id'];

Upvotes: 0

Vasu_Sharma
Vasu_Sharma

Reputation: 105

You can try this echo $row['task_id']; it will work....

Upvotes: 0

James
James

Reputation: 22247

You would do that by limiting your SQL query using a where clause to get the correct record.

Upvotes: 0

Arend
Arend

Reputation: 3761

It's won't work, because you need to iterate the whole $recordsArray to the the right $row.

You can solve this by saving a row as an hash in the $recordsArray instead of an enumurated array like this:

$recordsArray[$row['task_id']] = $row; 

Now you can fetch the row from the records array like this:

$recordsArray[$task_id];

(provided that $task_id exists).

Upvotes: 0

Stephane Gosselin
Stephane Gosselin

Reputation: 9148

You need quotes around the key for this to work:

 echo $row['task_id'];

Good-luck!

Upvotes: 4

Trey
Trey

Reputation: 5520

echo $row['task_id'];

maybe it's a syntax error?

Upvotes: 3

Related Questions