How do i select all from database and do while loop with them I did this easy select and im getting Error: Call to a member function fetchAssoc() on boolean , im beginner, im just trying to pull out two variables and make operations with them.

$result = db_select('cities', 'c')
        -&gt;fields('c')
        -&gt;execute()
        -&gt;fetchAssoc();



  while ($row = $result-&gt;fetchAssoc()) {

    $city_id = $row['city_id'];
  $city_name = $row['city_name'];


Only this is working for me 

     $sql = "SELECT * FROM {cities}";
           $result = db_query($sql);

  while ($row = $result-&gt;fetchAssoc()) {

    $city_id = $row['city_id'];
  $city_name = $row['city_name'];
Try with this:

   $results = db_select('cities', 'c')
    -&gt;fields('c')
    -&gt;execute()
    -&gt;fetchAll(PDO::FETCH_ASSOC);

   foreach ($results as $result){
    $city_id = $result['city_id'];
    $city_name = $result['city_name'];
   }