Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with tpl troubleshooting

    Hi, I am have a custom calendar application in use on our website. On the calendar, we have a search box that submits a text field to the search.php file which I am including here. When I enter a search term in which there is an occurance in the database, the php file works as expected, listing all the event names (the array value {result_name}) and times (array value {result_date}). When I enter no text (nul) it lists all of events in the database, again as designed. But when I enter a search term which does not occur in the database, the value printed in the htm template is {results_row_th}. It is outputting the explicit text of the tpl block.

    As I looked at this code, I realized that there is no empty set error handling. Since I am still learning php and I am maintaining this application I need to know where/how to check for an empty result set and where to add a default value to inform the user of the Empty Result.

    Here is the search.php code:
    Code:
    <?
    $GLOBAL_RIGHT_NOW = date("Y-m-d H:i:s");
    include("template.inc.php");
    include("funclib.inc.php");
    $tpl = new Template("templates/");
    $tpl->set_file("Template", "search_results_template.htm");
    $tpl->set_block("Template", "results_row", "results_row_th");
    $search_text = $GLOBALS['search_text'];
    $tpl->set_var("old_search", $search_text);
    $sql = "SELECT EVT_id, EVT_name, EVT_start FROM events WHERE ";
    $search_words = explode(" ", $search_text);
    $search_matrix = array();
    while ( list ($key, $value) = each ($search_words) ) {
        array_push($search_matrix, "EVT_name LIKE '%".$value."%'");
    }
    $sql .= implode (" OR ", $search_matrix);
    $link = mysql_connect($db_host, $db_user, $db_pass);
    mysql_select_db($db_db);
    $result = mysql_query($sql);
    while ( $row = mysql_fetch_object($result) ) {
        $epoch_start = glib_convert_to_epoch($row->EVT_start);
        $full_date = date("l F j Y", $epoch_start);
        $tpl->set_var(array("result_name" => "<a href=\"javascript:popup('http://www.website.com/austin/calendar/popup.php?mbid=".$row->EVT_id."',400,620);\">".strtoupper($row->EVT_name)."</a>",
                            "result_date" => $full_date));
        $tpl->parse("results_row_th", "results_row", true);
    }
    mysql_close($link);
    $tpl->parse("HTML", "Template");
    print $tpl->subst("HTML");
    ?>
    Thanks in advanced for the help!
    Skydiver

  • #2
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any suggestions would be helpful....

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was able to solve the problem lke this:

    Code:
    <?
    $GLOBAL_RIGHT_NOW = date("Y-m-d H:i:s");
    include("template.inc.php");
    include("funclib.inc.php");
    $tpl = new Template("templates/");
    $tpl->set_file("Template", "search_results_template.htm");
    $tpl->set_block("Template", "results_row", "results_row_th");
    $search_text = $GLOBALS['search_text'];
    $tpl->set_var("old_search", $search_text);
    $sql = "SELECT EVT_id, EVT_name, EVT_start FROM events WHERE ";
    $search_words = explode(" ", $search_text);
    $search_matrix = array();
    $result_count = 0;
    while ( list ($key, $value) = each ($search_words) ) {
        array_push($search_matrix, "EVT_name LIKE '%".$value."%'");
    }
    $sql .= implode (" OR ", $search_matrix);
    $link = mysql_connect($db_host, $db_user, $db_pass);
    mysql_select_db($db_db);
    $result = mysql_query($sql);
    while ( $row = mysql_fetch_object($result) ) {
        $epoch_start = glib_convert_to_epoch($row->EVT_start);
        $full_date = date("l F j Y", $epoch_start);
        $tpl->set_var(array("result_name" => "<a href=\"javascript:popup('http://www.website.com/austin/calendar/popup.php?mbid=".$row->EVT_id."',400,620);\">".strtoupper($row->EVT_name)."</a>",
                            "result_date" => $full_date));
        $tpl->parse("results_row_th", "results_row", true);
        ++$result_count;
    }
    	++$result_count;
    }
    if ($result_count == 0) {
        $tpl->set_var(array(
            "result_name" => "Sorry, your search resulted in no events.",
            "result_date" => '',
            "result_stage" => ''));
        $tpl->parse("results_row_th", "results_row", true);
    }
    mysql_close($link);
    $tpl->parse("HTML", "Template");
    print $tpl->subst("HTML");
    ?>
    Hope this helps anyone else with a similar problem. I was unimpressed with the help on this boards.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •