Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 866705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:51:12+00:00 2026-05-15T09:51:12+00:00

Sorry for the novice question! I have a table called cities in which I

  • 0

Sorry for the novice question!

I have a table called cities in which I have fields called id, name, xpos, ypos. I’m trying to use the data from each row to set a div’s position and name.

What I’m wondering is what’s the best practice for dynamically querying an unknown amount of rows (I don’t know how many cities there might be, I want to pull the information from all of them) and then passing the variables from the model into the view and then setting attributes with it?

Right now I’ve ‘hacked’ a solution where I run a different function each time which pulls a value using a query (‘SELECT id FROM cities;’), then I store that in a global array variable and pass it into view. I do this for each var so I have arrays called: city_idVar, city_nameVar, city_xposVar, city_yposVar then I know that the city_nameVar[0] matches up with city_xposVar[0] etc. Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:51:12+00:00Added an answer on May 15, 2026 at 9:51 am

    I’m not sure what you mean by “set a div’s position”, but here is an attemp:

    controller

    $data = array(
        'cities' => $this->cities_model->get_cities_info()
    );
    $this->load->view('view',$data);
    

    model

    function get_cities_info()
    {
      return $this->db->query('SELECT id, name, xpos, ypos FROM cities')->result();
    }
    

    view

    <?php foreach($cities as $city) : ?>
    <div style="position:absolute;top:<?= $city->ypos ?>;left:<?= $city->xpos ?>">
    <?=  $city->name ?>
    </div>
    <?php endforearch ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for a pretty specific question. I have a table (see bottom), and when
Sorry for this novice question: if I fit a lm() model or loess() model,
I'm a novice. Sorry. I'm trying to remove commas. Perl cgi.pm I need to
Sorry if this is a very novice question, I was just wondering one thing.
First of all Sorry if my question title sounds stupid.... I have the following
Sorry I realize this is a very novice question: I am not yet skilled
I'm sorry in advance if this question is really weird. I am sending data
Sorry for a long question and not a very descriptive title, but my problem
sorry for the lame question but with HTTP handler it is easy to do
Sorry if this is a stupid question... I've developed an application that creates absolute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.