Categories > TinyButStrong general >

Output ezSQL variables without merging

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Michaelsen
Date: 2005-12-16
Time: 08:38

Output ezSQL variables without merging


Hi there,

Is there anyway after I do this:

$company = $db->get_row("SELECT * FROM companies WHERE companyid = $_GET[companyid]");

I can output $company->name, $company->companyid etc without having to merge it? As if I could have [var.company.name], currently I need to define it such as $company->name = $companyName then use [var.companyName]. This would be a good thing because I can use ezsql to query cached results and retrieve some variables.

I appreciate any help and I'm sorry if this was addressed before, I couldn't find anything on the forums.

Best Regards,

- Michaelsen
By: Skrol29
Date: 2005-12-16
Time: 16:03

Re: Output ezSQL variables without merging

Hello,

The field [var.company.name] should work if $company is a an object and 'name' one of its properties.
I've tested your case with EzSql and it's working for me.

Did you checked that $company is an object as expected, and not a null value? This can happen if your query returns no data.



By: Michaelsen
Date: 2005-12-16
Time: 18:22

Re: Output ezSQL variables without merging

Well, this is a major problem with TBS, I never typed [var.company.name] because I never thought it could be that simple. We are so used with scripts giving us headaches all the time that is not an easy thing to get used with TBS easier-life methods. I apologize for that.

After reading your reply I also notice if I do:

$companies = $db->get_results("SELECT * FROM companies WHERE companyid = $_GET[companyid]");

foreach($companies as $company) {

//not needed

}

Then I have [var.company.companyid] available. However I can't figure out how to have the 2nd row as such [var.company.companyid.2] without doing the following:

$companies = $db->get_results("SELECT *
FROM categories
JOIN companies_categories ON companies_categories.catid = categories.catid
WHERE companies_categoriess.companyid = $_GET[companyid]");

foreach($companies as $company) {

$count++;

$companyCat[$count] = $company->catid;

}

Then I can have [var.companyCat.catid.1] and [var.companyCat.catid.2] when it is linked to 2 categories. I can't use the traditional method of block merging because both values will go inside little complex javascript select fields, then I can use no block definition. Or maybe perhaps what I'm doing is right also, would like to hear from you.

Thank you again.

Best Regards,

- Michaelsen
By: Skrol29
Date: 2005-12-16
Time: 22:03

Re: Output ezSQL variables without merging

Hello,

> I can't use the traditional method of block merging because both
> values will go inside little complex javascript select fields,
> then I can use no block definition.

You can undoubtedly merge blocks in Javascript using the explicit syntax (That is defining a block with two TBS tags : [blk;block=begin]...[blk;block=end]).
And, if necessary, you can use parameter "htmlconv=js" in a Field Tag in order to force its string value to be embeddable into Javascript strings.

>However I can't figure out how to have the 2nd row as such >[var.company.companyid.2] without doing the following:

If you have $companies = $db->get_results("...");
Then you can reach the value $companies[2]->companyid using the syntax:
[var.companies.2.companyid]
By: Michaelsen
Date: 2005-12-18
Time: 13:27

Re: Output ezSQL variables without merging

First let me thank you for your dedicated time with this thread, you are very kind.

I'm aware about the [blk;block=begin]...[blk;block=end] procedure, actually I use virtual tags such as <products>...</products>, amazing stuff by the way. However both categories will be on different select combo boxes.

I'm really impressed with the fact that if I just do $companies = $db->get_results("..."); I have all the values with no need for foreach or merging block, just one side note if I have 2 rows returned on the last example I'm going to access it starting at [var.companies.0.companyid], I didn't realize it at first.

Just to wrap it up, is it viable to use the get_results ezsql method when I'm going to never have more than 2 results returned on queries? Or the merge block is essential?

Thank you again.

Best Regards,

- Michaelsen
By: Skrol29
Date: 2005-12-18
Time: 15:30

Re: Output ezSQL variables without merging

> is it viable to use the get_results ezsql method when I'm going to never
> have more than 2 results returned on queries? Or the merge block is essential?

I think it is viable. Blocks are better when you have several rows to display because TBS makes only one Field analyze for each section. But two rows is  not much and you probably won't see the difference in therme of performance.
If you can have only one record two display then blocks will do it more easier.