Whistles and bells – tweaking the visual style

March 7, 2009 at 10:01 pm (Uncategorized)

 

Highlighting the active tab

I have had to fix something that has been bugging me for a while now. Whilst my fb:tab code was in a separate procedure so I could call it from any of my pages I could not on the fly change the highlighted tab.

This was rectified by use of some of the code from the smilie demo modified to fit my existing code:

 

As you can see it takes a parameter of the page it is currently on as well as the title to display

 

 

function render_headers2($title,$selected =’home’){
 

//create a header, tab highlight is done via selected attribute

$header = ” “;
    $header .=

    ‘<fb:tabs>’
             .’<fb:tab-item title=”Home”  href=”index.php” ‘
                     .’selected=”‘ . ($selected == ‘home’) .’” />’
        .’<FB:Tab-item href=”
http://apps.facebook.com/paulsfirstapp/findPlacement.php” title=”Finding a placement” selected=”‘ . ($selected == ‘findPlacement’) . ‘” />’
        .’<FB:Tab-item href=”
http://apps.facebook.com/paulsfirstapp/myPlacement.php” title=”My Placement” align=”right” selected=”‘ . ($selected == ‘myPlacement‘) . ‘” />’
        .’<FB:Tab-item href=”
http://apps.facebook.com/paulsfirstapp/addBlog.php” title=”Add a Blog Entry” align=”right” selected=”‘ . ($selected == ‘addBlog‘) . ‘” />’
        .’<FB:Tab-item href=”
http://apps.facebook.com/paulsfirstapp/testPage.php” title=”Sandbox” align=”right” selected=”‘ . ($selected == ‘testPage’) . ‘” />’
        .’<FB:Tab-item href=”
http://apps.facebook.com/paulsfirstapp/timeline.php” title=”Calendar” align=”right” selected=”‘ . ($selected == ‘calendar’) . ‘” />’
        .’<FB:Tab-item href=”
http://apps.facebook.com/paulsfirstapp/help.php” title=”Help” align=”right” selected=”‘ . ($selected == ‘help‘) . ‘” />’
    .’</fb:tabs>’;

 

}

As you can see it uses the ($selected == ‘findPlacement’) to evaulate to TRUE or FALSE and then sets the selected as necessary!

 

Fixing the Calendar

 

The easy php calendar that was causing trouble was due to the fact that the HTML code they provide assumes that it can use style sheets implicitly. TO overcome this I simply added an import using php so that the stylesheet is loaded each time the page is called using this line:

 

<style>
<?php echo htmlentities(file_get_contents(‘esstyle.css’, true)); ?>
</style>

and I copied the esstyle to the same directory as the calling page

 

Limit the result set from a SQL query

 

In the future I want to code the functionality to see any given blog posts from a user, my current workaround is to query the database using a limit statement selecting the first record and the number of subsequent records to use: ( note the . notation to concatenate)

 

function get_blogPosts($uid,$from,$to){

$query = “SELECT tblBlog.Date,tblBlog.Title,tblBlog.Entry,tblBlog.Tag1,tblBlog.Tag2,tblBlog.Tag3,tblBlog.PostNo FROM YearOutMYSQLDB.tblBlog WHERE userID =”.$uid.” Limit “.$from.”,”.$to.”;”;

}

 

Formatting 3 optional fields

 

When returning the tag options the user may have only filled in 1, 2 or 3 of the attributes and I was stuck how to show them in a single line without there being the chance of a large gap in the middle.

I fixed this with a quick isset function to append a comma to the field if it contained data:

 

if (isset ($tag1)){
        $tag1=$tag1.”,”;
    }
     if (isset ($tag2)){
        $tag2=$tag2.”,”;
    }

 

Passing multiple variables in the URL string using php in Facebook

 

Another minor issue that caused a headache but with a simple solution:

to add multiple variable simply join them with an ampersand ‘&’

 

e.g. www.mypageishere.com/index.php?action=addMe&myname=dave

 

note there is no ? for the second variable

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.