Question about embedding template using query tag to execute sql
Posted: 06 May 2008 01:11 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  66
Joined  05-06-2008

I have an existing site which uses php/mysql/ajax and I’m looking to move it to EE, but keep the existing functionality that currently exists… In particular I have a “contents” section of site which several pages use to execute sql and display the results through php..  These pages basically return the html to display using javascript to make an ajax call off of a menu item.  I would like to create a template which would be embedded inside of the “main” template, invoke the template passing the SQL select statement as a parameter to the ajax call and within the template use a {query tag to execute the select statement and display the results.... I’m not quite sure how/if this can be done through EE… I’m trying to avoid rebuilding the entire page with each call as most of the header/sidebar/footer information rarely changes....
Right now the “onclick” event for each menu item calls a javascript routine passing the url to invoke.. (eg.  onclick="getContentInfo(’./sermons.php’)".....
The getContentInfo call makes an ajax call and assigns the response text to the innerHTML of a div contained within the “main” page....
Can I do something like this using a “template_group/template” url along with an {embed tag and a {query tag within embedded template?
Thanks

Profile
 
 
Posted: 06 May 2008 04:25 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  2394
Joined  05-17-2002

It sounds as if you’ve already attempted this in EE. Are you already testing this somehow and its not going as planned? Or have you read through the docs and taking a best guess?

An EE template can use php and MySQL statements so what you describe should be feasible. If you already haven’t I’d recommend downloading EE Core, reviewing PHP in Templates and putting together a quick test of concept that way.

 Signature 
Profile
MSG
 
 
Posted: 06 May 2008 07:37 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  66
Joined  05-06-2008

I haven’t tried it yet.  I just took a quick look through the documentation and thought it might be possible using the embed and query tags… just not sure how that will fit in with doing a ajax call as the response from the call is “echoed” back by the php script and then assigned to the innerHTML of a div…

Profile
 
 
Posted: 07 May 2008 12:53 AM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1089
Joined  01-07-2008

If I understand this correctly, it should be possible natively.  If it isn’t, I’ll bet my pants a plugin can do it.  In fact, I’d be willing to write it.

My approach would be:
Javascript calls the ‘contents’ template with an additional segment to specify the page (i.e. template_group/contents_tmpl/sermons).

The contents template then uses the added segment as the table and runs the query.

{exp:query sql="SELECT {segment_3} FROM my_contents_table LIMIT 1"}

// This part 'should' work
{{segment_3}}

{
/exp:query}

The rest is done as always - get the responseText and update the div.

Untested, but hopefully this will put you on the right path.  As Leslie said, just play around with the core version a bit to get a feel for it.

 Signature 

Blog | Twitter | Coffee

Profile
 
 
Posted: 07 May 2008 09:45 AM   [ Ignore ]   [ # 4 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  21233
Joined  05-20-2002

Agreed- sounds pretty doable to me.  I know Godspy is using some ajax from a Jambor-ee tutorial in similar fashion (the ‘popular|recent’ links).  I’ve seen lots of other EE sites doing similar stuff, though methods may vary.

 Signature 

AKA rob1

Help Request Tips * Pro Network

Profile
 
 
Posted: 07 May 2008 10:18 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  66
Joined  05-06-2008

Ok,
I got that working…
I basically make a javascript call from a menu item (eg.

<a href="#" onclick="getContentInfo(’http://localhost/index.php/coc1/servicearea/bodylife’)">Body Life/Fellowship</a>

where bodylife is a template.  Many of the menu items contain data which is unique so they end up with their own template, but next will be using something like....

<a href="#" onclick="getContentInfo(’http://localhost/index.php/coc1/servicearea/seniors’)">Serving our Seniors</a>

where servicearea is a template and seniors will specify the type of information that I want to get back… my guess is I will have a weblog which contains the information for different service areas and I will limit it based on the information passed in the url....
That’s where my next question comes in....
I understand templates(display) and weblogs(data) at this point, but I’m trying to get a clear picture of where category groups/categories fit in....  I’ve been looking around trying to find a simple explanation of exactly how category groups/categories fit in… haven’t been able to find it yet… would “seniors” listed in url above be used as a category???

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 10:33 AM
Total Registered Members: 61061 Total Logged-in Users: 36
Total Topics: 73880 Total Anonymous Users: 16
Total Replies: 398518 Total Guests: 481
Total Posts: 472398    
Members ( View Memberlist )
Newest Members:  Dale-M Moeen uddinbnolenstanjadebieSan2kakifemreSchottec2kmeenazterjin