Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 6364 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi there,

I want to add a web page that says "Your Search has Found no Courses." I have the following code for search_for_courses.php:

<?php

include_once('FX/FX.php');

include_once('FX/server_data.php');

$course_name=$_REQUEST['course_name'];

$course_code=$_REQUEST['course_code'];

$starting_date=$_REQUEST['starting_date'];

$venue=$_REQUEST['venue'];

$venue_information=$_REQUEST['venue_information'];

$presenters=$_REQUEST['presenters'];

$stream=$_REQUEST['stream'];

$keyword=$_REQUEST['keyword'];

$new_course=$_REQUEST['newcourse'];

$type_of_search=$_REQUEST['type_of_search'];

if(isset($_REQUEST['skip'])){

$skipSize=$_REQUEST['skip'];

}else{

$skipSize='0';}

$groupSize='20';

if (isset($_REQUEST['page']) && is_numeric($_REQUEST['page'])) {

$skipSize = $groupSize * ($_REQUEST['page'] -1);

}

$Course_Search=new FX($serverIP,$webCompanionPort,'FMPro7');

$Course_Search->SetDBData('Course Information.fp7','Course Information',$groupSize);

$Course_Search->SetDBPassword('fmsadmin','fmsadmin');

if ($type_of_search == "OR") { $Course_Search -> AddDBParam('-lop', 'or'); }

$date = explode('/', $starting_date);

if(count($date)==3) $starting_date = $date[1] . '/' . $date[0] . '/' . $date[2];

$Course_Search->AddDBParam('Course_Name',$course_name, 'cn');

$Course_Search->AddDBParam('Course_Code',$course_code, 'eq');

$Course_Search->AddDBParam('Course_Date_First',$starting_date, 'eq');

$Course_Search->AddDBParam('Venue_Name',$venue, 'eq');

$Course_Search->AddDBParam('Stream_Name',$stream, 'eq');

$Course_Search->AddDBParam('Course_Description',$keyword, 'cn');

$Course_Search->AddDBParam('All_Presenters',$presenters, 'eq');

$Course_Search->AddSortParam('Sort_Order','descend');

$Course_Search->AddSortParam('Course_Date_First','ascend');

$Course_Search->FMSkipRecords($skipSize);

$Course_SearchResult=$Course_Search->FMFind();

$returnedCount=$Course_SearchResult['foundCount'];

echo $Course_SearchResult['errorCode'];

foreach($Course_SearchResult['data'] as $key=>$Course_SearchData);

$searchVariable=explode('.',$key);

$currentRecord=$searchVariable[0];

?>

***HTML goes here***

<?php

foreach($Course_SearchResult['data'] as $key=>$Course_SearchData){

$searchVariable=explode('.',$key);

$currentRecord=$searchVariable[0];

$course_URL = "find_this_course_single.php?recid=$currentRecord";

if ($Course_SearchData['Course_Capacity'][0] == 'Course Finished')

$course_URL = "course_details_no_reg.php?recid=$currentRecord";

if ($Course_SearchData['Course_Capacity'][0] == 'Course Has Started')

$course_URL = "course_details_no_reg.php?recid=$currentRecord";

if ($Course_SearchData['Course_Capacity'][0] == 'No longer accepting registrations')

$course_URL = "course_details_no_reg.php?recid=$currentRecord";

if ($Course_SearchData['Rescheduled'][0] == 'X')

$course_URL = "rescheduled.php?recid=$currentRecord";

if ($Course_SearchData['Course_Capacity'][0] == 'Full/Join Waiting List')

$course_URL = "waiting_list.php?recid=$currentRecord";

if ($Course_SearchData['Special_Course_1'][0] == 'RGF')

$course_URL = "course_details_DL_only.php?recid=$currentRecord";

if ($Course_SearchData['Special_Course_1'][0] == 'CP')

$course_URL = "course_details_DL_only.php?recid=$currentRecord";

?>

I need to add another if statement here that cuts in if the foundCount is zero but I cant work out how to code it. The second part of the statement would be something like

$course_URL = "no_courses_found.html";

Not sure if ?recid=$currentRecord"; needs to be added at the end of the above code since either no recid is found on a foundCount of zero or maybe the recid = 0 in such cases - Im not sure.

Posted

The php 'count' function (http://www.php.net/manual/en/function.count.php) will tell you how many elements are in an array. I'm not really up on the all the details of FX.php but it seems pretty clear your found record set is coming back in an array. It should be pretty easy to do your 'if' statement to check for zero array elements and take appropriate action.

Regards, Don

Posted

Counting items in a multipurpose array probably isn't the best idea.

There is a specific array key foundCount which is already being used above. If all you wanted to do was redirect the user if no records were found, something like this might work:

if( $returnedCount < 0 ) {

header( "Location: noRecords.php" );

exit();

}

Just ensure you put it in before you output any actual html to the browser.

But the whole redirect for error pages never really made sense to me, why aren't you just handling it in the same page?

This topic is 6364 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.