Pulling select fields from records

5 posts by 3 authors in: Forums > CMS Builder
Last Post: December 16, 2010   (RSS)

By MisterJim - December 16, 2010

Without resorting to straight SQL, how can you pull only specified fields from tables?

Normally, it would be something like:
SELECT title FROM <table>....

I can't see anyway to limit the fields that are selected using the commands that are accepted by CMS Builder.

Help?
WebCamp One, LLC



Websites That Work

Re: [Mr Jim] Pulling select fields from records

By Jason - December 16, 2010

Hi,

There isn't an option to limit the fields being returned by getRecords. The quickest way to do this would be to just use straight sql.

If you're interested, we can accomplish this for you with some customization.

Can you give an example where you would need to limit the number of fields returned without using plain sql?

Let me know.
Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Pulling select fields from records

By MisterJim - December 16, 2010

I am creating a website for a property management company. Each property has a LOT of fields. Using the CMS, I have a script that creates the main navigation on the fly by reading the entries to my main navigation table. At one point, I want it to jump into the properties table and just grab the 'title' and record number fields of each of the properties so that I can construct a link to each of them in a drop down menu off the main menu. In this example, it doesn't make sense to have to read in the entire properties table just to grab two fields.

As you said, I'll probably just go ahead and write this using regular sql.
WebCamp One, LLC



Websites That Work

Re: [Mr Jim] Pulling select fields from records

By Chris - December 16, 2010

Hi Mr Jim,

Sometimes straight SQL is the way to go. Something like this should work for you:

$escapedTableName = mysql_escape(getTableNameWithPrefix('my_section_name');)
$records = mysql_query_fetch_all_assoc("SELECT num, name FROM `$escapedTableName`");
showme($records);


I hope this helps! Please let me know if you have any questions.
All the best,
Chris