Best practices for querying an entire row in a database table? (MySQL / CodeIgniter)

Posted by Walker on Stack Overflow See other posts from Stack Overflow or by Walker
Published on 2010-06-17T01:22:20Z Indexed on 2010/06/17 1:22 UTC
Read the original article Hit count: 312

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about sql