completely understanding records lists and where to learn more

5 posts by 3 authors in: Forums > CMS Builder
Last Post: October 12, 2011   (RSS)

By rez - October 12, 2011 - edited: October 12, 2011

list($myRecords, $myMetaData) = getRecords(array(
'tableName' => 'my_table',
));

I know a variable is a container for info. An array is a list of values, each having an index. I remember they can get more complex with like, multiple values in each position. I've seen database tables and can look at some mySQL and sort of get what's happening. I understand the for each loops.

I want to understand what the results of the above list looks like exactly. Its an array, right? Or a list like here: http://php.net/manual/en/function.list.php ? I dont get the php list in the manual or how it is whats above. I know how to show all of the contents with the foreach generated code or a certain number of its contents with a counter. But if i could visualize the structure of what I am accessing, I think it may help me remember how this all works and what to learn next from other sources like the php site. ? Or is it CMSB code in there?

I know that myTable is the db table but only guess that $myRecords and $myMetaData are variables that this "list" constructor is populating from this table. Then I loop it out for display. I just don't get what it's putting into each of these variables, how it knows what to put in and what the final result looks like before I access it and where you are getting the more advanced code to manipulate it. The myMetaData is position markers or something? Is it used once when getting to the page to populate $myRecords (we never reference it in the dipslay?)

We display the results with foreach loops and each result can have a name, title, description and a bunch of pictures... so the list must be a list of arrays for each record? That could get complicated.

Hoping to understand this. And what do you recommend I look into next to get more advanced with CMSB past the documentation? Arrays and basic mySQL? Seems like whenever you lose me on answers or go outside the documentation, you are using those things? The line where CMSB ends and PHP and mySQL begins has been been blurry for me. Is CMSB a bunch of functions and in between your code and the display are these lists?

thanks.

Re: [rez] completely understanding records lists and where to learn more

Hi Rez,

Three suggestions.

One is to look for answers to questions here in the forum. The more specific the better.

The second is to explore my CMSB Cookbook thecmsbcookbook.com for more on how to accomplish various advanced tasks.

The third would be to do exactly what you've done here. Post specific questions on the forum.

Hope that gives you some ideas.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] completely understanding records lists and where to learn more

By rez - October 12, 2011

Thanks Jerry. I look for answers in the forum all the time. I also have your cookbook. I'm trying to put the missing pieces together. I'm doing too much that works and only basically understanding what's going on. I used to work at a micro lab where everyone just followed the procedures. I took home the manuals and a medical dictionary to understand the inner workings of all the machines. Eventually people were coming to me for answers when things went wrong and I advanced quickly as the problem solver for situations in other labs / states.

Although I dont want to solve everyone elses problems here and will never match people like Jason, I want to learn more and understand the inside of the machine. Maybe then i'll know exactly what PHP and mySQL to learn? Where is my manual to cross reference with the PHP site or a Lynda tutorial? I feel like i could watch a lynda tutorial on PHP and mySQL but it still may not apply exactly to where i should go next here?

Re: [rez] completely understanding records lists and where to learn more

By Jason - October 12, 2011

Hi,

You're right, the lines between CMSB, PHP, and MySQL do get a little blurry. In its most basic sense, CMS Builder is a collection of functions written is PHP to allow you to easily manipulate information inside a MySQL database. The getRecords() function, for example, is a PHP function we wrote that takes some simple options from you and uses that to create SQL statements which it executes and then returns the results.

In the case of your first question concerning list(), if we take a look at the example you gave:

list($myRecords, $myMetaData) = getRecords(array(
'tableName' => 'my_table',
));


there are a couple of different things going on. Basically, getRecords will take all of the records from the table "my_table" and put them into the array $myRecords.

The list() part is a PHP language construct that allows us to return multiple variables with a single return statement. What it does is takes an array, and assigns each part of the array a variable in the list. The getRecords() function is actually returning an array of arrays. If we look at the return statement inside that function, this is what we see:

return array($rows, $listDetails, $schema);

$rows is an array of all the records being returned. $listDetails is an array of information about those records (ie, how many were returned, how many pages of information there will be, which page are we currently on, etc). Finally $schema is the schema of the section the records came from. list() takes each one of these arrays and assign them to a variable: $rows gets assigned to $myRecords, $listDetails gets assigned to $myMetaData.

A great way to see the structure of what's being returned is to use the CMSB function showme(). If you pass an array to this function, it will show you a break down of how the entire array is structured and what is stored in each element. So, to see exactly what the results of your getRecords call, you could do this:

list($myRecords, $myMetaData) = getRecords(array(
'tableName' => 'my_table',
));

showme($myRecords);
showme($myMetaData);


Hope this helps to clarify a little. I find the best way to learn is to experiment with the different functions you come across, whether they're from PHP or CMS Builder. This is something I still do all the time when working with different parts of CMS Builder. If you ever get stuck, let us know and we'll see if we can explain it more clearly.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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