PHP
The very least you need to know about PHP in order to build a custom web solution using the FileMaker API for PHP. Start with these basics then read all articles tagged PHP.
Tags
Enclose php code within these brackets.
<?php echo "Go Gophers!"; ?>
Echo
What you put within PHP tags is inaccessible to the outside world. When you want to show something on a web page, use echo.
<?php echo "Go Gophers!"; ?>
Semicolon
Separate arguments with a semicolon.
<?php $teamAcolor = "maroon"; $teamBcolor = "gold"; ?>
Comments
Use double forward slashes to comment out a line of code. This is handy for documenting chunks of code:
//Add product to shopping cart
or troubleshooting you can disable and isolate the offending line.
$findCommand->addFindCriterion('rt_Format', $format);
//$findCommand->addFindCriterion('rt_Audience', $audience);
$findCommand->addFindCriterion('rt_Subject', $subject);
Variables
Variables stand in for other pieces of data. They are a convenient and efficient way to refer back to strings or arrays. They begin with a dollar sign. They are case sensitive, so if you define $StudentType, don't refer back to $studentType. In recent PHP releases, you need to define a variable before you attempt to refer to it so $rate * $qty won't work unless you define $rate and $qty earlier in the page.
Arrays
Arrays are beautiful, efficient, powerful... and maddening to the newbie. With their initial dollar sign they're indistinguishable from variables but your code will error if you confuse the two. They hold tons of data but you can't see what it is until you explicitly ask for it. FileMaker search results are returned as arrays so you'll need to get comfortable with them. Here's a visual.
if this is a variable...
this an array...
and this is an associative array.
Set a variable.
$color = "maroon";
Set an array.
$colors = array("maroon", "gold");
Set an associative array.
$bigten = array ( "state" => "Minnesota"; "mascot" => "Gopher" ), array ( "state" => "Wisconsin"; "mascot" => "Badger" ) );
Leave a comment