0

I have a database table (gpx_api) with the following fields:

runID   userID  score   distance    pace    speed   gpx_path    missionID   startTime   duration 

I want to display all of these fields from within a module.

I have searched a lot on stack and I got until here:

   $query = db_select('gpx_api', 'run')
     ->fields('run')
     ->condition('runID', $firstparameter, '=')
     ->execute()
     ->fetchAssoc();

Do I only select the row where runID = $firstparameter like this?

This should only return one result. Now how can I display the fields one by one?

$query->distance 

will not work.

I also tried

foreach($query as $result2){
 $result .="DISTANCE";
$result .= $result2->distance;
  }

This strangely enough gave a lot of results and errors.

I am sure there is a very simple way, but I am not familiar with the drupal API.

--Update

a var_dump of query gives me:

array(10) { ["runID"]=> string(1) "2" ["userID"]=> string(1) "1" ["score"]=> string(2) "10" ["distance"]=> string(3) "200" ["pace"]=> string(1) "7" ["speed"]=> string(1) "8" ["gpx_path"]=> string(0) "" ["missionID"]=> NULL ["startTime"]=> NULL ["duration"]=> NULL } 

so it is just about displaying the array. Shouldn't $query->distance work then? Yet if I try it, I get this error:

Notice: Trying to get property of non-object in epicrun_mymenu_page_callback() (line 62 of /home/suneesto/public_html/addons/epicrunapp.com/sites/all/modules/epicrun/epicrun.module).
1

Basic php error, it's $query['distance']

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.