I am trying to return a list of projects which I can do via the following code: (this is part of a larger if statement, that is why the dangling { bracket in the foreach line)
foreach ($r->getRecords() as $project){
echo $project->getField('Project_Name') .'<br />';
That returns the list just as it should. I am now trying to link each of the returned $project variable to a URL (each project will re-direct to another page showing project details.) Here is what I have tried.
foreach ($r->getRecords() as $project){
echo '<a href="project_detail.php">' $project->getField('Project_Name') '</a>' .'<br />';
That returned a syntax error on the
foreach ($r->getRecords() as $project){
echo $project->getField("<a href='project_detail.php'>'Project_Name'</a>") .'<br />';
Any advice or a nudge in the right direction would be appreciated.
To be able to link to a project you're going to need to pass in some kind of identifier for the link so that your project_detail.php
file knows what project record to find. In the code below I make the assumption that the id field of the project record id called id
.
// Please never use single letter variables in your code.
foreach ($result->getRecords() as $project){
$projectId = $project->getField('id'); // This should be whatever primary key field (serial number field) you define for your project
$projectName = $project->getField('Project_Name');
echo "<a href='project_detail.php?id=$projectId'>$projectName</a><br>";
}
If you write the data you need into variables first, you can then use a double quote string to construct the link and use the variable names without having to concatenate everything. You end up with a couple of extra lines of code but your link string is way more readable.
Now your project_detail.php
file can use the project id value to find the project record:
$projectId = $_GET['id'];
$findRequest = $fm->newFindCommand('project_layout_name');
$findRequest->addFindCriterion('id', $projectId);
$findResult = $findRequest->execute();
....
You can try this :
echo '<a href="project_detail.php">' $project->getField('Project_Name') '</a>' .'<br />';
Missing Concatenating (.)
echo '<a href="project_detail.php">'.$project->getField('Project_Name').'</a><br />';