Categories > TinyButStrong general >

MergeBlocks need a php variable from another mergeblock

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: hozyali
Date: 2010-08-02
Time: 22:07

MergeBlocks need a php variable from another mergeblock

Hi,

As the subject defines, I need to pass a sub category ID to my 2nd Mergeblock SQL. I could not find a way to do it, can someone please help?

Here is the example I need to do.

$TBS->MergeBlock('MainMenu',$localhost,"Select * from ".$GLOBALS['pre_tbl']."categories where cat_parent = 0 and cat_status=1 order by cat_rank ASC");

$TBS->MergeBlock('SubMenu',$localhost,"Select * from ".$GLOBALS['pre_tbl']."categories where cat_parent = $MainCatID order by subcat_rank ASC");
so you see the SubMenu block has a variable for where clause $MainCatID. But I can't find a way to popuplate this variable from the MainMenu block.

Please help.

thanks
By: Skrol29
Date: 2010-08-02
Time: 22:48

Re: MergeBlocks need a php variable from another mergeblock

Hi, Hozyali,

This is the purpose of subblocks.
See alone examples and also the manual:
  http://www.tinybutstrong.com/manual.php#html_block_subblock
By: hozyali
Date: 2010-08-02
Time: 23:31

Re: MergeBlocks need a php variable from another mergeblock

thanks Skrol29,

I got it. but can you tell me how do I echo the actual statement to verify that my sql query is working or not?

Because, when I pass the variable to the subcat query, its not returning what it should.

thanks for your help.
By: Skrol29
Date: 2010-08-02
Time: 23:42

Re: MergeBlocks need a php variable from another mergeblock

Hi,

Try with TbsSQL, it has a trace mode.
But take the 3.0-beta, this is the only one where the trace mode works with TBS's MergeBlock.

The beta is available here:
http://sourceforge.net/projects/tinybutstrong/files/
By: hozyali
Date: 2010-08-02
Time: 23:45

Re: MergeBlocks need a php variable from another mergeblock

don't really want to go in that much.

actually the subcategory table and fields are also same, it just checks if the cat_parent field is equal to maincat id.

the result shows me the same result as the main cat. that means that the varible in 2nd sql is empty and defaults to 0 itself.

please advise.
By: Skrol29
Date: 2010-08-03
Time: 01:20

Re: MergeBlocks need a php variable from another mergeblock

Can you post your new MergeBlock commands and a snippet for block and subblock ?


By: hozyali
Date: 2010-08-03
Time: 08:30

Re: MergeBlocks need a php variable from another mergeblock

yes here it is

below is the Blocks code with the variable
$TBS->MergeBlock('MainMenu',$localhost,"Select * from ".$GLOBALS['pre_tbl']."categories where cat_parent = 0 and cat_status=1 order by cat_rank ASC");
$TBS->MergeBlock('SubMenu',$localhost,"Select * from ".$GLOBALS['pre_tbl']."categories where cat_parent = '%catparent%' order by subcat_rank ASC");


here is the template blocks

<div class="main-nav">
    <ul>
      <li name="[MainMenu.cat_id]"><a href='category.php?cid=[MainMenu.cat_id]'><span>[MainMenu.cat_name;block=li;catparent=MainMenu.cat_id]</span></a></li>
    </ul>
   
    <ul class='sub-nav' id="subnav_[MainMenu.cat_id]" style='display: inline;'>
      <li name="[SubMenu.cat_id]"><a href='category.php?cid=[SubMenu.cat_id]'><span>[SubMenu.cat_name;block=li]</span></a></li>
    </ul>
  </div>

Also can you advise what language support should we implement, I mean should implement language by using static language files made in php or mysql? what is efficient to make a robust application?

appreciate your help.

thanks
By: Skrol29
Date: 2010-08-03
Time: 09:40

Re: MergeBlocks need a php variable from another mergeblock

Hi,

First the subblock feature is activated since there is a "p1" parameter in the subblock definition in the template side.
Thus you should replace
[SubMenu.cat_name;block=li]
with
[SubMenu.cat_name;block=li;p1=[MainMenu.cat_id]]
Embeded TBS field is not a problem here because MainMenu is merged before SubMenu.

You also have to use %p1% in the SQL query:
$TBS->MergeBlock('SubMenu',$localhost,"Select * from ".$GLOBALS['pre_tbl']."categories where cat_parent=%p1% order by subcat_rank ASC");
if column "cat_parent" is numerical, you don't need the text delimiters.


The last think to have it working is that the main block should surround the subblock. This is quite logical, the main block has to make the subblock be repeated.

So you should replace
[MainMenu.cat_name;block=li;catparent=MainMenu.cat_id]
with
[MainMenu.cat_name;block=div]
your parameter "catparent" is ignored by TBS.

By: Skrol29
Date: 2010-08-03
Time: 09:42

Re: MergeBlocks need a php variable from another mergeblock

> should implement language by using static language files made in php or mysql

Can you precise your question ?
By: hozyali
Date: 2010-08-03
Time: 09:51

Re: MergeBlocks need a php variable from another mergeblock

hi,

I mean should I make language files for example

/lang/english.php
/lang/french.php

OR

I should manage languages from mysql database

thanks
By: hozyali
Date: 2010-08-03
Time: 09:58

Re: MergeBlocks need a php variable from another mergeblock

regarding your suggestion about the menu, it worked but not exactly. now it removed the main category names and just showed all the subcats.

anyway, I wanted to know this.

Is there any nice CSS drop down you know which is either already integrated to TBS or much easier to integrate?

I just want to populate sub categories when mouse hovers on a main category. I will be using this menu on top of my website under header.

thanks a lot for your help.
By: Skrol29
Date: 2010-08-03
Time: 10:48

Re: MergeBlocks need a php variable from another mergeblock

About multilanguage support, I would say that if you've designed your application having in mind that the texts are part of the design, and should be managed by technical people only, the it should be in a PHP file. Like most of the CMS I've met do.

In the other hand, if you put them in SQL, then you can develop a screen to add more language and have translations made of fixed by other users.

There is also a topic about TBS and multi-language here:
http://www.tinybutstrong.com/forum.php?msg_id=2714#

By: hozyali
Date: 2010-08-03
Time: 21:51

Re: MergeBlocks need a php variable from another mergeblock

Hi,

I have got the menu category issue sorted and its working fine now.

I have another question.

I have a block with recordset and its looping.
In the template, I need to put a condition.

Here is an example of my php code

while ($EvListing = mysql_fetch_assoc($RsEventsList)) {
if ($EvListing['type'] =='shows'){

$currenttable="shows";
$gotopage="shows";
$urldir = 'shows';
$imgdir = "shows_images";
}else{

$currenttable="artists";
$gotopage="tickets";
$urldir="tickets";
$imgdir = "artist_images";
}

The above code basically sets the directory names depending on the mysql field value. I think the above code is self explanatory.

Kindly help how do I do this using TBS template.

Thanks
By: hozyali
Date: 2010-08-03
Time: 21:56

Re: MergeBlocks need a php variable from another mergeblock

I also need to take array or field values in PHP using MergeBlock, can you please advise how can I do that?

for example

$TBS->MergeBlock('BlkEvents',$localhost,"SELECT * FROM ".$GLOBALS['pre_tbl']."TblName where cat_id = '$catid' ORDER BY date_time DESC");

from the above query, I need the itemID in PHP to do other actions. Please help